0
雖然定義指令時通過屬性和作用域使用變量,但有什麼區別?例如 -AngularJs屬性vs指令中的作用域
angular.module('tModule')
.directive('tModule', function() {
return {
restrict: 'E',
scope: true,
templateUrl: function(element, attributes) {
return attributes.variable1;
}
}
});
與如果我使用範圍。如下 -
angular.module('tModule')
.directive('tModule', function() {
return {
restrict: 'E',
scope: {
variable1: "=variable1",
variable2: "=variable2"
},
templateUrl: function() {
return variable1;
}
}
});
有什麼區別和優勢?
當需要雙向數據綁定時使用'='。當你想要控制器和指令之間的雙向數據綁定時使用它。 – dhavalcengg