angularjs - Angular JS two way binding not updating when using button -


i'm bit of newb @ angular , having persnickety issue. trying update variable bound div in controller function, called when button clicked. (the function bound button ng-click.) when click button, displayed value not change, though variable changed. if assign same updating function element change when click element. can explain? here's code:

javascript

angular.module('compendium',['ngroute']) .config(function($routeprovider){     $routeprovider.when('/css',{         templateurl:'css.html',          controller: 'cssctrl'     }) }).controller('cssctrl',function($scope,counterhelper){     //counterhelper($scope.data) //counter.increment();      $scope.increment = function(){         alert('hey');       $scope.display = 'nothing'     }      $scope.display = 1;        // var transform = function(){       //    }).factory('counterhelper',function(){     var addone = function(val){         val ++;     }     return addone; }) 

and html

<html ng-app = "compendium"> <head> <script src = "node_modules/angular/angular.js"> </script> <script src = "node_modules/angular-route/angular-route.js"> </script> <script src = "app.js"></script> <script type="text/ng-template" id="css.html">   <h1 ng-controller = 'cssctrl' ng-click='increment()'>     {{display}}     </h1>     <button ng-click = 'increment()' >increment</button> </script> </head> <body> <div ng-view> </div> </body>  </html> 

thanks!

problem here controller outside button hence not recognize controller attached, wrap inside div

<div ng-controller = 'cssctrl'>   <h1  ng-click='increment()'>     {{display}}   </h1>   <button ng-click = 'increment()' >increment</button> </div> 

Comments