scope and controller instantiation with ui router

To get even more detailed answers, we can/should observe the source code and check the documentation. Let me try to explain all three questions (and also cite from code and doc). 1. When do controllers get instantiated? Here we can observe the code of the ui-view directive: [$ViewDirective.$inject = \[‘$state’, ‘$injector’, ‘$uiViewScroll’, ‘$interpolate’\];][1] Controllers are … Read more

AngularJS event on window innerWidth size change

We could do it with jQuery: $(window).resize(function(){ alert(window.innerWidth); $scope.$apply(function(){ //do something to update current scope based on the new innerWidth and let angular update the view. }); }); Be aware that when you bind an event handler inside scopes that could be recreated (like ng-repeat scopes, directive scopes,..), you should unbind your event handler when … Read more

Angular controller scope not updating after jQuery ajax call

Disregarding other architectural issues I pointed out in the comments, the real issue is that you’re using jQuery‘s ajax instead of Angular’s $http. When you don’t do things like that through Angular, you’re working outside of Angular’s scope and it doesn’t know about changes. While not ideal, you can use $scope.$apply to let angular know … Read more

Binding inputs to an array of primitives using ngRepeat => uneditable inputs

Can anyone explain to me why are the inputs uneditable/readonly? If it’s by design, what’s the rationale behind? It is by design, as of Angular 1.0.3. Artem has a very good explanation of how 1.0.3+ works when you “bind to each ng-repeat item directly” – i.e., <div ng-repeat=”num in myNumbers”> <input type=”text” ng-model=”num”> When your … Read more