@Directive({ selector: '[myHighlight]' })
@Directive 裝飾器需要一個(gè) css 選擇器,以便從模板中識(shí)別出關(guān)聯(lián)到這個(gè)指令的 HTML
這是從官網(wǎng)上面例子copy下來(lái)的,有一個(gè)疑問(wèn):@Directive 裝飾器是不是要從所有模板上面找出myHighlight這個(gè)選擇器?如果是這樣的話,不是很耗資源嗎?一般情況下不是應(yīng)該指定某個(gè)模板裡面找?
文檔上寫的很清楚:
應(yīng)該是在目前模板找所有符合這個(gè)選擇器的元素,很耗資源是你感覺(jué)的。其實(shí)跟jquery的選擇器沒(méi)什麼兩樣。@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.