試圖通過使用單向綁定來加載指令中的數據是代碼。
<nav-directive depts="dummyData"></nav-directive>
APP.directive('navDirective', navDirective);
這裏是指令時,數據由電腦板更新
function navDirective($state, navigationService,$rootScope) {
return {
restrict: "E",
scope: { depts: '=' },
templateUrl: '/app/shared/common-directives/navigation/navigation.view.html',
link: function(scope, elem, attr) {
$rootScope.$watch('depts', function(newVal, oldVal) {
// or $watchCollection if students is an array
if (newVal) {
console.log('in Dir');
console.log(scope.depts)
}
},true);
}
};
}
scope.depts是不確定的。
爲什麼'$ rootScope。$ watch'?嘗試'範圍。$ watch'。我想'$ rootScope'中只有'depts'才能被觀察 – k102