Javascript 如何使用尖括号呈现HTML注释<;!--{{myModel.myProperty}-->;
如何使用尖括号呈现HTML注释?Javascript 如何使用尖括号呈现HTML注释<;!--{{myModel.myProperty}-->;,javascript,angularjs,Javascript,Angularjs,如何使用尖括号呈现HTML注释? 它呈现文字 <div data-ng-switch='field.TypeAsString'> <label for="{{field.InternalName}}" class="control-label">{{field.Title}}:</label> <!-- FieldName="{{field.odata.type}}" FieldInternalName="{{field.Int
它呈现文字
<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>
{{field.Title}}:
返回
<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 -->
标题:
我想要的答案是:
对注释调用指令的语法为:
我希望像ng bind这样的东西能够支持评论,但事实并非如此。但您可以轻松创建自己的:
应用指令('comment',函数($interpolate){
返回{
限制:‘M’,
范围:正确,
链接:函数(范围、元素、属性){
var comment=$interpolate(attrs.comment)(范围);
元素。替换为(“”);
}
};
});
用法是:
根本不清楚你在问什么,或者你希望有什么不同。请说得更具体些
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}}" -->