Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very simple ng-model watch not working

Tags:

angularjs

Here is the jsfiddle. http://jsfiddle.net/CLcfC/

code

var app = angular.module('app',['']);

app.controller('TestCtrl',function($scope){
    $scope.text = 'Change Me';
    $scope.$watch('text',function(){
        alert('Changed !');
    });


})

HTML

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<div ng-app="app">
 <div ng-controller="TestCtrl">
     <input type="text" ng-model='text'/>
     <span>{{text}}</span>
  </div> 
</div>

I am not able to see the change in $scope.text. Please help. This is so easy but what am I missing?

like image 410
lostpacket Avatar asked Dec 25 '22 20:12

lostpacket


1 Answers

Change the module creation to this, make sure you don't put a empty string in the []. (Obvious the empty string is not a module that can be injected.)

var app = angular.module('app', []);

Demo: http://jsfiddle.net/MWa66/

like image 57
zs2020 Avatar answered Jan 21 '23 08:01

zs2020