为什么在AngularJS指令中不推荐使用`replace`属性? [英] Why is `replace` property deprecated in AngularJS directives?
问题描述
根据 API文档,指令'替换
属性已被弃用,因此将来所有指令都将使用当前默认值替换:false
。
According to the API docs, directives' replace
attribute is deprecated, so in the future, all directives will behave with the current default of replace: false
.
这消除了开发人员替换元素指令元素的能力,没有明显的替代对于此功能。
This removes developers' ability to replace an element directive's element, with no apparent replacement for this functionality.
有关元素指令如何工作的示例,请参阅此插件有和没有替换:true
。
See this plunk for an example of how element directives work with and without replace: true
.
为什么这个有用的属性被弃用而没有替换?
Why is this useful attribute being deprecated with no replacement?
推荐答案
更新
其中一位合作者表示它不会被删除,但已知的错误将无法修复。
https://github.com/angular/angular.js/commit/eec6394a342fb92fba5270eee11c83f1d895e9fb# commitcomment-8124407
One of the collaborators has said it won't be removed, but known bugs will not be fixed. https://github.com/angular/angular.js/commit/eec6394a342fb92fba5270eee11c83f1d895e9fb#commitcomment-8124407
ORIGINAL
这是提交的此更改:
https://github.com/angular/angular.js/commit/eec6394a342fb92fba5270eee11c83f1d895e9fb
替换
标志,用于定义替换元素$ b $的指令b他们所在的将在下一个主要角度版本中删除。
此功能具有困难的语义(例如属性如何合并)
并且与其解决的问题相比会导致更多问题。另外,使用
WebComponents在DOM中拥有自定义元素是正常的。
The
replace
flag for defining directives that replace the element that they are on will be removed in the next major angular version. This feature has difficult semantics (e.g. how attributes are merged) and leads to more problems compared to what it solves. Also, with WebComponents it is normal to have custom elements in the DOM.
听起来像是它的组合复杂性与维持支持的好处之比。
It sounds to me like its a combination of complexity vs benefit to maintain support.
显然开发人员之所以使用它是因为他们更喜欢注入语义正确的标记,从而替换自定义指令标记。
And apparently one reason dev were using it because they prefered semantically correct markup to be injected , thus replacing the custom directive tag.
阅读该链接下方的评论,显然很多人希望它留下来。
Read the comments lower down on that link and apparently many people want it to stay.
这篇关于为什么在AngularJS指令中不推荐使用`replace`属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!