如何呈现带尖括号的HTML注释<!--{{myModel.myProperty}}-->

How to render HTML comments with angular brackets? <!-- {{myModel.myProperty}} -->

本文关键字:myModel myProperty gt 何呈现 HTML 注释 lt      更新时间:2023-09-26

如何呈现带尖括号的HTML注释
它呈现文字。

<div data-ng-switch='field.TypeAsString'>
    <label for="{{field.InternalName}}" class="control-label">{{field.Title}}:</label>
    <!-- FieldName="{{field.odata.type}}"
     FieldInternalName="{{field.InternalName}}"
     FieldType="{{field.odata.type}}"
      -->
    <span data-ng-switch-when='Text'>
      <input id="{{field.InternalName}}" class="form-control" data-ng-model="field.value" type='text' />
    </span>
</div>

返回

<div data-ng-switch="field.TypeAsString" class="ng-scope">
<label for="Title" class="control-label ng-binding">Title:</label>
<!-- FieldName="{{field.odata.type}}"
 FieldInternalName="{{field.InternalName}}"
 FieldType="{{field.odata.type}}"
  -->
<!-- ngSwitchWhen: Text --><span data-ng-switch-when="Text" class="ng-scope">
    <input id="Title" class="form-control ng-pristine ng-valid ng-empty ng-touched" data-ng-model="field.value" type="text">
</span><!-- end ngSwitchWhen: -->
<!-- ngSwitchWhen: Note -->
<!-- ngSwitchWhen: Number -->
<!-- ngSwitchWhen: Choice -->
<!-- ngSwitchWhen: Lookup -->

我正在寻找的答案:如何插入带有插值表达式的HTML注释?

The syntax to invoke a directive on a comment is:
<!-- directive: foo expression -->
I was hoping that something like ng-bind supported comments, but it doesn't. But you could easily create your own:
app.directive('comment', function($interpolate) {
  return {
    restrict: 'M',
    scope: true,
    link: function(scope, element, attrs) {
      var comment = $interpolate(attrs.comment)(scope);
      element.replaceWith("<!-- " + comment + "-->" );
    }
  };
});
And the usage is:
<!-- directive: comment "something something {{item.id}}" -->