angualrJs指令起名的bug

來源:互聯網
上載者:User

標籤:旋轉   字串   pil   編譯   注意   執行   頁面   append   users   

我在寫一個demo時:

<div ng-repeat="user in users" my-template2 my-template>  //my-template2 和my-template 是我寫的兩個指令,注意我起的指令名

然後在實際使用中:
.directive("myTemplate",function () {
return{
restrict : "EACM",
replace : true,
compile : function (tElement, tAttrs, translude) {
console.log("1 正在編譯!"); // 總是 先 指令 myTemplate 編譯, 然後 myTemplate2在編譯
tElement.append(angular.element("<div>aaaa1</div>")); //tip : 這裡會觸發,但是頁面上卻沒有。
return function () {
console.log("1 的 compile 下的 postLink 已執行!");
}
}
}
})
.directive("myTemplate2",function () {
return{
restrict : "EACM",
template:‘<div>{{user.name}}</div>‘,
compile : function (tElement, tAttrs, translude) {
tElement.append(angular.element("<div>aaaa2</div>"));
console.log("2 正在編譯!");

return {
pre : function preLink() {
console.log("2 preLink 函數");
},
post: function postLink() {
console.log("2 postLink函數");
}
};
},
link : function () {

}
}
})
/**
結論: 如果你的起名類似 xx 和 xx + “其他的字串”(比如: demoDer 和 demoDersss) ,且他們作用在同一個元素上時, 優先順序相同時, xx 總是會先編譯(也許是他短-->我很短,但是我可以旋轉),且對他的dom調整會失效。
當你換了一個名字的時候比如demoDer1 和 demoDers 時, 就會恢複正常。
這是我發現的一個現象 我的angualr版本是 :
v1.2.16
聽說angualr 已經4.00 不知道新的版本還有這個問題嗎? 有待測試。

*/


angualrJs指令起名的bug

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.