gpt4 book ai didi

javascript - Angular Comment 指令 - 目的/意图/最佳实践

转载 作者:行者123 更新时间:2023-11-30 11:56:04 30 4
gpt4 key购买 nike

通读,http://www.w3schools.com/angular/angular_directives.asp我遇到了一个在评论中调用指令的例子,具体来说:

<!-- directive: w3-test-directive -->

您可以在 http://www.w3schools.com/angular/tryit.asp?filename=try_ng_directive_comment 中看到它的工作原理

这让我很担心。有人可以描述一下您希望评论中的某些内容像这样执行的目的或意图吗?乍一看,它看起来像是糟糕的设计,也许需要避免?如果我错了,我想了解何时使用的意图/目的和最佳实践。

最佳答案

这是来自 Angular 的文档

Best Practice: Comment directives were commonly used in places where the DOM API limits the ability to create directives that spanned multiple elements (e.g. inside elements). AngularJS 1.2 introduces ng-repeat-start and ng-repeat-end as a better solution to this problem. Developers are encouraged to use this over custom comment directives when possible

但是,最好不要使用它们,如此处所示

Best Practice: Prefer using directives via tag name and attributes over comment and class names. Doing so generally makes it easier to determine what directives a given element matches.

https://docs.angularjs.org/guide/directive

关于javascript - Angular Comment 指令 - 目的/意图/最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37924755/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com