I have an angular directive that looks like this:
myApp.directive('foo', function() {
return {
template: '<span>{{foo.bar}}</span>',
restrict: 'E',
scope: true,
controller: 'myController'
};
});
EDIT I set the directive initially with this controller:
myApp.controller('myController', function ($scope, MyModel) {
$scope.foo = MyModel.get();
});
and it seems to work fine to modify the model from a second controller:
myApp.controller('myOtherController', function($scope, MyModel) {
setTimeout(function() {
MyModel.set({
bar: "biz"
});
}, 3000);
});
but not with this controller code:
myApp.controller('myOtherController', function($scope, MyModel) {
$http.get("/resource").then(function(response) {
MyModel.set(response.data);
});
});
I have confirmed that the model updates in both instances, but the directive does not update the view with the $http request.
Here is a Plunker that will give you the general idea.
I have tried all sorts of $timeout/$scope.$apply solutions and they all either do nothing or through a digest in progress error. Any help would be appreciated
MyModel
service look like? – Phil