如何设置仅限于在评论指令angularjs属性 [英] How to set up attributes in angularjs directive restricted to comments
本文介绍了如何设置仅限于在评论指令angularjs属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现在angularjs不错的功能。指令可以被设置为在评论工作。
{
...
限制:'M'
...
}
这是卓有成效的,因为它是在文档中发言。这个指令的使用方法如下:
< - 指令:!我-指令名称 - >
和就好,只要我不需要将参数传递给这个指令它的工作原理。
是否有可能限制设置要发表评论,指令参数呢?
什么是语法?
解决方案
< - 指令:!我-指令名,这是所有的参数 - >
凡指令名后一切都传递到配置参数的值。
app.directive('myDirectiveName',函数(){
返回{
限制:'M',
链接:功能(范围,ELEM,ATTR){
警报(attr.myDirectiveName); //警报这是所有的参数
}
};
});
I've found nice feature in angularjs. Directives can be set to work on comments.
{
...
restrict: 'M'
...
}
This does the trick as it is spoken in the documentation. Usage of this directive is as follows:
<!-- directive: my-directive-name -->
And it works just fine as long as I don't need to pass arguments to this directive. Is it possible to set arguments on directive restricted to comment? What's the syntax?
解决方案
<!-- directive: my-directive-name this is all an argument -->
Where everything after the directive name is the value passed into the directive.
app.directive('myDirectiveName', function(){
return {
restrict: 'M',
link: function(scope, elem, attr) {
alert(attr.myDirectiveName); //alerts "this is all an argument"
}
};
});
这篇关于如何设置仅限于在评论指令angularjs属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文