javascript - angular/ionic ng-click not updating the view, however it is updated in the model -


i having serious difficulties updating view in ionic/angular when using ng-click.

i came across similar issue earlier on solved following this guidance, explains if button inside < label > ng-click not work.

what trying achieve?

i developing mobile application , want allow user edit details if necessary. in effort start off have began trying implement functionality whereby user can edit name. in example below trying change name of user when button clicked.

the strange thing when console.log(photos.name) correct value, i.e.(scope.user.name = "jim") view not reflect change.

the code have follows:

controller

.controller('profilectrl', function($scope, photos) {      $scope.user = {         "name": photos.name     }      $scope.changename = function() {         photos.changename();         console.log(photos.name)     };  }) 

factory:

.factory('photos', function(){   var o = {     name : 'james'   }    o.changename = function(){     o.name = 'jim'   }    return o;  }); 

html settings template

this button updates user's name on profile.html page(see below)

 <ion-view view-title="settings">       <ion-content>         <ion-list>        <div class="item item-input">         <span class="input-label">change profile picture</span>         <button type="button" ng-click="changename()">add</button>       </div>      </ion-list>     </ion-content>  </ion-view> 

profile template

<ion-view view-title="my profile">   <ion-content class="padding">      <div class="item item-body">      <p class="profile-details">         {{user.name}}      </p>     </div>   </ion-content> </ion-view> 

i have read through many answers , on ionic webpage, no luck. have read think may setting value in child scope thing breaking cannot sure.

can help?

i believe reason once this:

$scope.user = {     "name": photos.name } 

you set value of $scope.user.name value of photos.name @ that moment.

when change photos.name doing o.name = 'jim' within factory, you're assigning photos.name different string object, not changing 1 assigned $scope.user.name.

you can prove theory doing $scope.user = photos instead of $scope.user = { ... } (just quick proof of concept, of course, rather final solution). way $scope.user.name access name value that's being held in photos factory.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -