我在控制器中有对象
$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']时,手表不起作用。