angular.js - 关于angular属性指令的疑问
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:06:18
[AngularJS讨论组]

@Directive({ selector: '[myHighlight]' })
@Directive 装饰器需要一个 css 选择器,以便从模板中识别出关联到这个指令的 HTML

这是从官网上面例子copy下来的,有一个疑问:@Directive 装饰器是不是要从所有模板上面找出myHighlight这个选择器?如果是这样的话,不是很耗资源吗?一般情况下不是应该指定某个模板里面找?

曾经蜡笔没有小新
曾经蜡笔没有小新

全部回复(1)
某草草

文档上写的很清楚:

@Directive requires a CSS selector to identify the HTML in the
template that is associated with our directive. The CSS selector for
an attribute is the attribute name in square brackets. Our directive's
selector is [myHighlight]. Angular will locate all elements in the
template that have an attribute named myHighlight.

应该是在当前模板找所有符合这个选择器的元素,很耗资源是你感觉的。其实和jquery的选择器没什么两样啊。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号