removing the ng-init and just populating the scope var in your controller works: http://plnkr.co/edit/4vHi5B?p=preview
I went to check out the docs of ngInit and found: http://docs.angularjs.org/api/ng/directive/ngInit The only appropriate use of ngInit is for aliasing special properties of ngRepeat <http://docs.angularjs.org/api/ng/directive/ngRepeat>, as seen in the demo below. Besides this case, you should use controllers<http://docs.angularjs.org/guide/controller> rather than ngInit to initialize values on a scope. So yeah...don't do it that way :). No need for the watch when model is tied to a scope property. On Tuesday, March 25, 2014 9:57:51 PM UTC-5, ru ga wrote: > > Hi all, > > I've built a application with AngularJs and NodeJs, view template EJS. > When I render a page, I set value of input (ng-model) and I want to get > that model in controller but I can't get it. > This is my file EJS: > > <!DOCTYPE html> > <html ng-app='test'> > <head> > <script src="/angular/angular.js"></script> > <link rel='stylesheet' href='/stylesheets/style.css' /> > </head> > <body ng-controller='testCtrl'> > <input type="text" ng-model='testModel' ng-change='change()' > ng-init="testModel ='John'"> > </body> > </html> > > <script> > var testApp = angular.module('test', []); > > testApp.controller('testCtrl', function($scope){ > $scope.change = function(){ > console.log($scope.testModel); > }; > console.log($scope.testModel); > }); > </script> > > Anyone can help me please? > Thanks and Best Regards, > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
