Angular指令 //创建指令模块 (或者检索现有模块) var m = angular.module("myApp");// 创建"my-dir"指令 myApp.directive("myDir", function() { return { restrict: "E", // 指令是一个元素 (并非属性) scope: { // 设置指令
//创建指令模块 (或者检索现有模块)
var m = angular.module("myApp");
// 创建"my-dir"指令
myApp.directive("myDir", function() {
return {
restrict: "E", // 指令是一个元素 (并非属性)
scope: { // 设置指令对于的scope
name: "@", // name 值传递 (字符串,单向绑定)
amount: "=", // amount 引用传递(双向绑定)
save: "&" // 保存操作
},
template: // 替换HTML (使用scope中的变量)
"
" +
" {{name}}:
" +
"
" +
"
",
replace: true, // 使用模板替换原始标记
transclude: false, // 不复制原始HTML内容
controller: [ "$scope", function ($scope) { … }],
link: function (scope, element, attrs, controller) {…}
}
});
