0

In html :

<md-card-title-text ng-controller="ProfileCtrl">
  <span ng-model="user.displayName" class="md-headline">userName</span>
  <span ng-model="user.email" class="md-subhead">user@abc.com</span>
</md-card-title-text> 

In angularjs code:

angular.module('authApp')
  .controller('ProfileCtrl', function($scope) {
    $scope.user = {};
    $scope.user.displayName = localStorage.username;
    $scope.user.email = localStorage.email;
    console.log($scope.user.displayName)
  }); 

The problem is that ng-model doesn't update when scope value changed in controller. How can I solve this problem ?

Manish Balodia
  • 1,863
  • 2
  • 23
  • 37
Hongbin Wang
  • 1,186
  • 2
  • 14
  • 34
  • Use `ng-bind` instead of `ng-model` for `span` – dex Apr 08 '16 at 12:56
  • Possible duplicate of [AngularJS - ng-model fails on ](http://stackoverflow.com/questions/23528478/angularjs-ng-model-fails-on-span) – Dexygen Apr 08 '16 at 13:04

2 Answers2

1

Try to use ng-bind for span: AngularJS - ng-model fails on <span>

angular.module('authApp')
    .controller('ProfileCtrl', function ($scope) {
        $scope.user = {displayName : 'userName', email: 'user@abc.com'};
        $scope.user.displayName = localStorage.username;
        $scope.user.email = localStorage.email;
        console.log($scope.user.displayName)
});

Html:

<md-card-title-text ng-controller="ProfileCtrl">
     <span ng-bind="user.displayName" class="md-headline"></span>
     <span ng-bind="user.email" class="md-subhead"></span>
</md-card-title-text>

or just <span class="md-headline">{{user.displayName}}</span>

Community
  • 1
  • 1
a.u.b
  • 1,589
  • 10
  • 25
0

You can use

<md-card-title-text ng-controller="ProfileCtrl">
   <span class="md-headline">{{user.displayName}}</span>
   <span class="md-subhead">{{user.email}}</span>
</md-card-title-text>

or

ng-bind-html="user.email"