This works pretty cool man. Thanks i try to found on internet but you save my lots of time.
Thanks On Friday, December 13, 2013 at 5:23:00 PM UTC+1, Daniel Tabuenca wrote: > > Usually this is due to another directive in-between your ng-controller and > your input that is creating a new scope. When the select writes out it > value, it will write it up to the most recent scope, so it would write it > to this scope rather than the parent that is further away. > > The best practice is to never bind directly to a variable on the scope in > an `ng-model`, this is also known as always including a "dot" in your > ngmodel. For a better explanation of this, check out this video from John: > > http://www.youtube.com/watch?v=DTx23w4z6Kc > > > > > On Friday, December 13, 2013 7:41:24 AM UTC-8, Martijn Vos wrote: >> >> I'm utterly stumped about this one: >> >> I've got a property, pageSize, that is originally set in the controller, >> but can be updated through a select box. When I change the select box, >> data-bindings in the view get updated, but not the one in the controller's >> scope, and I don't understand why. >> >> Everything else works fine. I've got only one controller that does >> everything else it's supposed to do. I'm calling update() from ng-change >> which works fine. And in the update(), I log the value of $scope.pageSize, >> but that value never changes, despite the {{pageSize}} just above my select >> showing the new value. >> >> How is this possible? >> >> HTML: >> {{pageSize}} >> <select name="pageSize" id="pageSize" ng-model="pageSize" >> ng-change="update();"> >> <option value="5">5</option> >> <option value="10">10</option> >> <option value="25">25</option> >> <option value="50">50</option> >> </select> >> >> Controller: >> $scope.pageSize = 5; >> >> $scope.update = function() { >> console.log("pageSize = "+$scope.pageSize); >> reviewService.fetch({ >> pageSize: $scope.pageSize, >> }).success(function(data, status) { >> console.log("success!"); >> $scope.reviewData = data.d; >> $scope.nrOfPages = >> Math.ceil($scope.reviewData.summary.ReviewCount / $scope.pageSize); >> }).error(function(data, status) { >> console.log("error!"); >> $scope.error = true; >> }); >> } >> $scope.update(); >> >> So to be clear: >> * $scope.update() gets called correctly by ng-change. >> * the log($scope.pageSize) always logs '5'. >> * {{pageSize}} shows the value I selected. >> >> >> mcv. >> > -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/e634a0f0-c40c-4dae-9e33-838740cd3720%40googlegroups.com.
