1
  <div class="popover-content" ng-click="updateHeader('jack')">

When this div is clicked it calls a function which makes a get request and


var app = angular.module('myApp', []);
app.controller('myContoller', function($scope, $http) {

$scope.username = "";
$scope.updateHeader = function(username) {

 var url = "api?user="+ username;
 $http.get(url)

 .then(function(response) {
   $scope.username = response.data.plugUser;
   console.log($scope.username);
   $scope.scrollableChatItems = response.data.msg;

       });
   };

};

Even though the console.log is working it is printing the username in the console, It is not updating in the username.why the username is not updating?


<div class="container" ng-controller="myController">
                    <h3 class="content-box-header">
                        {{username}}
                    </h3>
2
  • Is the "popover-content" div inside the "container" div with the ng-controller??? Commented Oct 13, 2016 at 18:06
  • inside the ng-controller Commented Oct 13, 2016 at 18:15

2 Answers 2

2

Make sure your div is placed inside the ng-controller div

   <div class="container" ng-controller="myController">
      <div class="popover-content" ng-click="updateHeader('jack')">
         <h3 class="content-box-header">
           {{username}}
        </h3>
       </div>
    </div>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks,It works.but why it was not working before.ng-init is for setting the default value.It has to called the function but why it is not setting the username
0

Fix typo your controller name. myContoller

var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {

$scope.username = "";
$scope.updateHeader = function(username) {

 var url = "api?user="+ username;
 $http.get(url)

 .then(function(response) {
   $scope.username = response.data.plugUser;
   console.log($scope.username);
   $scope.scrollableChatItems = response.data.msg;

       });
   };

};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.