課程
/前端開(kāi)發(fā)
/Angular
/AngularJS實(shí)戰(zhàn)
templateCache如何讓多個(gè)指令去使用?
2016-09-30
源自:AngularJS實(shí)戰(zhàn) 2-9
正在回答
$templateCache是module里面的全局對(duì)象,同一個(gè)模塊里的指令都可以共享一個(gè)$templateCache
var?myModule?=?angular.module("MyModule",?[]); //注射器加載完所有模塊時(shí),此方法執(zhí)行一次 myModule.run(function($templateCache){ ???$templateCache.put("hello.html","<div>Hello?everyone!!!!!!</div>"); }); myModule.directive("hello",?function($templateCache)?{ ????return?{ ????????restrict:?'AECM', ????????template:?$templateCache.get("hello.html"), ????????replace:?true ????} }); myModule.directive("hi",?function($templateCache)?{ ????return?{ ????????restrict:?'AECM', ????????template:?$templateCache.get("hello.html"), ????????replace:?true ????} });
qq_噎死愛(ài)肚_03411770 提問(wèn)者
$templateCache.html里面增加了"hi"指令嘛?按你的做法,我這有效果啊
這樣不起作用 頁(yè)面中調(diào)用第二個(gè)指令沒(méi)效果
javdroider
qq_噎死愛(ài)肚_03411770 提問(wèn)者 回復(fù) javdroider
舉報(bào)
一起學(xué)習(xí)AngularJS的基礎(chǔ)教程,通過(guò)實(shí)例學(xué)習(xí)并學(xué)會(huì)AngularJS
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-09-30
$templateCache是module里面的全局對(duì)象,同一個(gè)模塊里的指令都可以共享一個(gè)$templateCache
2016-10-13
$templateCache.html里面增加了"hi"指令嘛?按你的做法,我這有效果啊
2016-10-10
這樣不起作用 頁(yè)面中調(diào)用第二個(gè)指令沒(méi)效果