AngularJS指令限制A对ê [英] AngularJS Directive Restrict A vs E
问题描述
我在一个小团队工作,建设AngularJS并试图保持一些基本的标准和安培;最佳做法;尤其是考虑到我们正在与角度比较新的。
I'm working in a small team, building in AngularJS and trying to maintain some basic standards & best practices; especially given we're relatively new with Angular.
我的问题是关于指令。更准确地说,限制
选项。
My question is with regards to Directives. More accurately, the restrict
options.
我们中有些人正在使用限制:'E'
因而具有<我的指导性和GT;< /我-指令>
在HTML
Some of us are using restrict: 'E'
thus having <my-directive></my-directive>
in the html.
别人都在用限制:'A'
并具有&LT; DIV我-指令&GT;&LT; / DIV&GT;
在HTML
Others are using restrict: 'A'
and having <div my-directive></div>
in the html.
然后,当然,你可以使用限制:EA
,并使用上述其中之一。
Then, of course, you can use restrict: 'EA'
and use either of the above.
目前,它没什么大不了的,但是当这个项目是大,因为它会得到我想任何人都看着它很容易明白发生了什么事情。
At the moment it's no big deal, though when this project is as big as it's going to get I would like anybody looking at it to easily understand what's going on.
是否有优点/缺点要么做事情的属性或元素的方法吗?
Are there pros/cons to either the attribute or element way of doing things?
是否有我们应该知道的陷阱,如果说选择了元素属性?
Are there any pitfalls we should know, if choosing say element over attribute?
推荐答案
根据文档:
什么时候应该使用与元素属性?使用元素时
要创建一个组件,它是在模板的控制。该
这种常见的情况是,当你正在创建一个域特定
语言模板的一部分。当你使用属性
装饰用新的功能已有的元素。
When should I use an attribute versus an element? Use an element when you are creating a component that is in control of the template. The common case for this is when you are creating a Domain-Specific Language for parts of your template. Use an attribute when you are decorating an existing element with new functionality.
的编辑以下为一个完整的答案上的缺陷评论:的
假设你正在构建应该在Internet Explorer&LT运行应用程序; = 8,其中支持已经从AngularJS 1.3下降了AngularJS的球队,你必须遵循,以使其工作以下说明:的 https://docs.angularjs.org/guide/ie
Assuming you're building an app that should run on Internet Explorer <= 8, whom support has been dropped by AngularJS team from AngularJS 1.3, you have to follow the following instructions in order to make it working: https://docs.angularjs.org/guide/ie
这篇关于AngularJS指令限制A对ê的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!