I want to watch an array changes inside Angular controller and update HTML view.
this is my controller:
app.controller("timelineCtrl", function ($scope) {
$scope.arr=[];
.
.
.
}
this is my directive:
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: true,
template: '<div> Hello {{arrayItem}} </div>',
link: function ($scope, element, attrs) {
$scope.$watch($scope.arr, function(newValues, oldValues) {
$scope.arrayItem = newValues;
});
}
};
});
I add some new values to array via button click but my $watch doesn't work. How can i overcome this?