为什么 AngularJS 指令中不推荐使用`replace` 属性? [英] Why is `replace` property deprecated in AngularJS directives?
问题描述
根据 API 文档中,指令的 replace
属性已弃用,因此将来所有指令都将使用当前默认的 replace: 错误
.
这使开发人员无法替换元素指令的元素,但没有明显替换此功能.
请参阅this plunk,了解元素指令在使用和不使用 replace: true
的情况下如何工作的示例.>
为什么这个有用的属性被弃用而没有替换?
UPDATE
其中一位合作者表示不会删除它,但不会修复已知错误.https://github.com/angular/angular.js/commit/eec639298230ec6392782304b1b18c8304ec639278304b/a>
原创
这是此更改的提交:https://github.com/angular/angular.js/commit/eec6394a342fb92fba51dc89fb92fba51dc85eee>p<块引用> 对我来说,这听起来像是维持支持的复杂性与好处的结合. 显然开发人员使用它的一个原因是因为他们更喜欢注入语义正确的标记,从而替换自定义指令标签. 阅读该链接下方的评论,显然很多人希望保留它. According to the API docs, directives' This removes developers' ability to replace an element directive's element, with no apparent replacement for this functionality. See this plunk for an example of how element directives work with and without Why is this useful attribute being deprecated with no replacement? UPDATE 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 Here is the commit of this change:
https://github.com/angular/angular.js/commit/eec6394a342fb92fba5270eee11c83f1d895e9fb The 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屋!replace
标志,用于定义替换元素的指令将在下一个主要角度版本中删除它们.此功能具有困难的语义(例如,如何合并属性)与它解决的问题相比,会导致更多的问题.此外,与WebComponents 在 DOM 中有自定义元素是正常的.replace
attribute is deprecated, so in the future, all directives will behave with the current default of replace: false
.replace: true
.
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.