2
我有一個隔離範圍的指令。我想檢測作爲父範圍變量的屬性的更改。在模型屬性更改中傳遞的角度指令檢測
我見到目前爲止以下內容:
var app = angular.module("app", []);
app.controller("ctrl", function($scope, $timeout) {
$timeout(function() {
console.log("called");
$scope.isReady = true;
$scope.$apply();
}, 2000);
});
app.directive("car", function($log) {
return {
scope: {
make: "=carMake"
},
restrict: 'E',
template: "<strong ng-bind='make'></strong>",
link: function(scope, elem, attrs) {
scope.$watch(attrs.shouldDo, function(value) {
var val = value || null;
if (val) {
$log.info(scope.$eval(attrs.shouldDo));
}
}, true);
}
}
});
http://fiddle.jshell.net/8Qhuk/
如果我設置範圍爲false
它的作品,但我需要它有一個孤立的範圍內工作。
是!這就是訣竅!太好了,謝謝! :) – Mantisimo