</pre>1,控制器使用<p></p><p></p><p></p><p></p><pre name="code" class="javascript">myAppModule.directive('hello', function () {
return {
restrict:"AEMC",
template:"<div>hello</div>",
templateUrl:"a.html"
replace:true
}
});
myApp.directive("myDir", function() {
return {
restrict: "E", // 指令是一个元素 (并非属性)
scope: { // 设置指令对于的scope
name: "@", // name 值传递 (字符串,单向绑定)
amount: "=", // amount 引用传递(双向绑定)
save: "&" // 保存操作
},
template: // 替换HTML (使用scope中的变量)
"<div>" +
" {{name}}: <input ng-model='amount' />" +
" <button ng-click='save()'>Save</button>" +
"</div>",
replace: true, // 使用模板替换原始标记
transclude: false, // 不复制原始HTML内容
controller: [ "$scope", function ($scope) { … }],
link: function (scope, element, attrs, controller) {…}
}
});
2,templateCache在控制中的使用
</pre><p></p><pre name="code" class="javascript">myAppModule.run(function ($templateCache) {
$templateCache.put("key","value");
});
myAppModule.directive('temlateurl', function ($templateCache) {
return {
restrict:"AEMC",
template: $templateCache.get("key");
templateUrl:"a.html"
replace:true
}
});