我創建了一個應用程序,其中我有一個指令,我正在監視指令內的某個表,以在指令內觸發某些方法在$ rootScope變量的變化,但問題是當$ rootScope.name值改變手錶這是指令中沒有工作
我的代碼如下
給出var module = angular.module('myapp', []);
module.controller("TreeCtrl", function($scope, $rootScope) {
$scope.treeFamily = {
name : "Parent"
};
$scope.changeValue = function()
{
$rootScope.name = $scope.userName;
};
});
module.directive("tree", function($compile) {
return {
restrict: "E",
transclude: true,
scope: {},
template:'<div>sample</div>',
link : function(scope, elm, $attrs) {
function update()
{
};
scope.$watch('name', function(newVal, oldVal) {
console.log('calling');
update();
}, true);
}
};
});
你能告訴我笏是我正在做的問題 – 2014-12-03 08:06:54
你不能直接使用rootcope裏面的指令。使用範圍使用2種方式進行綁定:{name:'='} – simon 2014-12-03 08:11:52