My problem: I can modify my model fine, and the changes are reflected in my view, as long as my view is hidden. As soon as my view is un-hidden, changes made to scope.food.foo from timeouts, event handlers, etc. no longer apply. This is all within a directive.
Fiddley: http://jsfiddle.net/9T9qE/1/
I am using an object as my model (instead of using the scope as my model, which causes problems with inheritance) That is, I'm using scope.food.foo instead of simply scope.foodFoo
html:
<div ng-app="myApp">
<my-directive></my-directive>
</div>
js:
myApp = angular.module("myApp", []);
myApp.directive("myDirective", function() {
var d = {};
d.restrict = "E";
d.template = '<div ng-show="food.show">hi, I like <input type="text" ng-model="food.foo"> and, in case you forgot, that\'s {{food.foo}}</div><button ng-click="food.show = true">show me</button>';
d.link = function(scope, element, attrs) {
scope.food = {};
scope.food.foo = "pie";
scope.food.show = false;
setTimeout(function() {
alert("timeout: setting scope.food.foo = 'cake'");
scope.food.foo = "cake";
}, 6000);
};
return d;
});