javascript - ionic ng-model do not works correct -


i'm working on ionic project. don't know why, ng-model not work correct.i have started new project default starter called tabs

when open browser see "my custom text" in input field, when change it, in console see same text "my custom text", should changed input. changes not applied on $scope.getusername. tried debug , found creates own $scope inside $scope of dashctrl, when tried access $scope.child got undefined.

can explain me what's going on , doing wrong?

here code www/js/controllers.js

angular.module('starter.controllers', [])  .controller('dashctrl', function($scope) {      $scope.getusername = 'my custom text';      $scope.namechange = function(){        console.log($scope.getusername);      };  })  .controller('chatsctrl', function($scope, chats) {   // new view caching in ionic, controllers called   // when recreated or on app start, instead of every page change.   // listen when page active (for example, refresh data),   // listen $ionicview.enter event:   //   //$scope.$on('$ionicview.enter', function(e) {   //});    $scope.chats = chats.all();   $scope.remove = function(chat) {     chats.remove(chat);   }; })  .controller('chatdetailctrl', function($scope, $stateparams, chats) {   $scope.chat = chats.get($stateparams.chatid); })  .controller('accountctrl', function($scope) {   $scope.settings = {     enablefriends: true   }; }); 

and www/templates/tab-dash.html

<ion-view view-title="dashboard">   <ion-content class="padding">     <h2>welcome ionic</h2>      <input ng-model="getusername" ng-change="namechange()"  name="anim" class="my-input"          aria-describedby="inputdescription" />     <p>     ionic starter tabs-based apps. other starters , ready-made templates, check out <a href="http://market.ionic.io/starters" target="_blank">ionic market</a>.     </p>     <p>       edit content of each tab, edit corresponding template file in <code>www/templates/</code>. template <code>www/templates/tab-dash.html</code>     </p>     <p>     if need app, join ionic community on <a href="http://forum.ionicframework.com" target="_blank">ionic forum</a>. make sure <a href="http://twitter.com/ionicframework" target="_blank">follow us</a> on twitter important updates , announcements ionic developers.     </p>     <p>       sending push notifications, join <a href="https://apps.ionic.io/signup" target="_blank">ionic platform</a> , check out <a href="http://docs.ionic.io/docs/push-overview" target="_blank">ionic push</a>. have other services available.     </p>   </ion-content> </ion-view> 

hey guys figured out problem.

i replaced ng-model="getusername" ng-model="userobject.username" , same in the/controllers.js

so looks this

.controller('dashctrl', function($scope) {      $scope.userobject = {         username: 'custom'     }      $scope.namechange = function(){        console.log($scope.userobject.username);      };  }) 

to understand why works check out article.

https://github.com/angular/angular.js/wiki/understanding-scopes


Comments