12

我在 angularjs 中找到了不错的功能。可以设置指令以处理评论。

{
    ...
    restrict: 'M'
    ...
}

正如文档中所说,这可以解决问题。该指令的用法如下:

<!-- directive: my-directive-name -->

只要我不需要将参数传递给该指令,它就可以正常工作。是否可以在仅限于评论的指令上设置参数?语法是什么?

4

1 回答 1

19
<!-- directive: my-directive-name this is all an argument -->

指令名称之后的所有内容都是传递给指令的值。

app.directive('myDirectiveName', function(){
   return {
      restrict: 'M',
      link: function(scope, elem, attr) {
          alert(attr.myDirectiveName); //alerts "this is all an argument"
      }
   };
});
于 2012-10-29T17:43:29.340 回答