angular.js - 關於angular屬性指令的疑問
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:06:18
0
1
532

@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 .3. all elements in the
template that have an attribute named myHighlight.

應該是在目前模板找所有符合這個選擇器的元素,很耗資源是你感覺的。其實跟jquery的選擇器沒什麼兩樣。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!