javascript - AngularJS not updating? -


i'm not sure why not changing when bound object changes:

my html:

 <div id="account-info" ng-controller="authenticatectrl">      <h5>account: </h5>      {{account}}  </div>  <div ng-controller="authenticatectrl">     <div modal="shouldbeopen" options="opts">         <div class="modal-header">             <h3>select account</h3>         </div>         <div class="modal-body">             <div class="account-btn" ng-repeat="item in items" ng-click="close(item)">                 {{item}}             </div>         </div>     </div> </div> 

my javascript:

var authenticatectrl = function ($scope) {     $scope.account= "";      $scope.open = function() {         $scope.shouldbeopen = true;     };      $scope.close = function(item) {         if (item) {             $scope.shouldbeopen = false;             $scope.account= item;         }     }; } 

for reason displays nothing, or if set $scope.account = "any string" display "any string" won't update when close function called.

ok attempt fiddle. firstly had 2 ng-controller directives pointing same function. secondly don't understand domain here, i'm guessing need. heres fiddle.

<div ng-controller="authenticatectrl"> <div id="account-info">      <h5>account: </h5>      {{account.name}}  </div>  <div>     <div modal="shouldbeopen" options="opts">         <div class="modal-header">             <h3>select account</h3>         </div>         <div class="modal-body">             <div class="account-btn" ng-repeat="item in items" ng-click="close(item)">                 {{item.name}}             </div>         </div>     </div> </div>    </div>  <script> var myapp = angular.module('myapp',[]);  var authenticatectrl = function ($scope) {      $scope.opts = {};     $scope.account = {};      $scope.items = [         {'name':'one'},         {'name':'two'}     ];      $scope.open = function() {         $scope.shouldbeopen = true;     };      $scope.close = function(item) {         if (item) {             $scope.shouldbeopen = false;             $scope.account= item;         }     }; } </script> 

Comments