0
我有對象控制器角指令表不走了
$scope._id = '12345';
$scope.messages = {
'12345': [
{
author: 'Vasya',
message: 'Message from Vasya'
},
{
author: 'Bob',
message: 'Message from Bob'
}]
};
HTML標記:
<div message-list="{{_id}}")></div>
我的指令:
var App = angular.module('app', [])
.directive("messageList", function() {
return {
link: function(scope,element,attrs) {
scope.$watch('messages[attrs.messageList]', function(newVal,oldVal) {
if (newVal!==oldVal)
{
console.log("newVal",newVal);
console.log("oldVal",oldVal);
}
},true);
}
}
});
,但看不,當我工作將新元素推入數組$ scope.messages ['12345']。
如果我是正確的,你想觀看的範圍是「指令範圍」,並且不與控制器範圍相關,其中的對象「消息「是。 嘗試直接在控制器中觀看或使用Rootcope。 $ root351, – icchio