Rk Reddy Bairi Rk Reddy Bairi -4 years ago 132
AngularJS Question

angular expression in html view rendering same data for different expressions

Angular expressions on one of my view are rendering same data on screen

it would show : hello - hello ( for different expressions {{a}}, {{b}} )

There is cleary different data binded to 'a' and 'b' variables in controller.

html view :

{{ a | json }} - {{ b | json }}


angular controller:

app.controller('myctrl', function($scope, myservice) {

var self = this;

self.getA = function() {
$scope.a = 'hello';
}

self.getB = function() {
$scope.b = 'hey';
}

self.getA(); //call on controller startup
self.getB();

});

Answer Source

Your code works without any issue,

Make sure you are doing the following.

DEMO

var app = angular.module('myctrl',[]);
app.controller('myctrl', function($scope) {
      var self = this;
      self.getA = function() {
        $scope.a = 'hello';
      }
      self.getB = function() {
        $scope.b = 'hey';
      }
      self.getA(); //call on controller startup
      self.getB();

});
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Dashboard</title>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body >
<div ng-app="myctrl" >
<div ng-controller="myctrl as ctrl" >
 {{ a }} - {{ b }}
</div>
</div>
</body>
</html>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download