我有一个如下所示的指令:
directive('parcelsCarousel',function () {
return {
restrict:'E',
replace:true,
transclude:true,
templateUrl:'/partials/parcels-carousel.html',
link:function (scope, element, attrs) {
scope.$watch('favoriteParcelsList', function (favoriteParcelsList) {
if (scope.favoriteParcelsList != undefined)
console.log(scope.favoriteParcelsList.length)
});
}
}
});
我从控制器推送一个项目favoriteParcelsList
,但 $watch 没有运行。我该怎么办?我确信我遗漏了一些小东西,因为我有几个其他具有类似结构的指令并且它们工作正常。