I can not get the two ways data binding working in AngularJS directive.
Here is my html code from the template, used with a basic controller instantiating mymodel (an array here) :
HTML
<select ng-if="mymodel" multipleselect values="mymodel">
DIRECTIVE
I have a directive called multipleselect :
return {
restrict: 'A',
scope : {
values : '='
},
link : function($scope, element, attrs){
...
$scope.values = ["some","nice","datas"]; //Actually works, the model is changed in the controller
$("select").change(function(){ //This is a callback, asynchronous situation
$scope.$apply(function () { //Using apply to notify the controller that we are changing its model
$scope.values = ["some","amazing","datas"]; //Not working :(
});
});
}
}
Why my model is not updated the second time I change it ?