I have a array defined in controller and passing it to directive using two way binding. In directive, i tried to pushed object into that array but it failed.
.controller("test", function($scope){
$scope.myarr =[];
$scope.$watch("myarr", function(newValue, oldValue){
console.log($scope.myarr); //prints empty arr
},true);
});
.directive('ptest', ['$compile', function($compile) {
var object = {value: 'changed value'};
return {
restrict:"E"
scope: {
myarr:"="
},
template : "<div>{{iobj.value}}<div>",
link: function(scope,elem,attr){
myarr.push(object) ;
}
};
}]);
html
<ptest myarr="myarr"></ptest>