在AngularJS中
Model改变了,在Controller**不会**通知
例子有空再举例子
https://docs.angularjs.org/api/ng/type/$rootScope.Scope
http://www.learn-angular.org/#!/lessons/watch
这段代码可以实现对输入model进行监听$watch
注意watch的第一个函数是字符串(model名)
<!doctype html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div ng-controller="myController">
<p>成绩:<input ng-model="name"></p>
<p>绩点:{{gpa}}</p>
</div>
<script src="angular.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller('myController', function ($scope) {
$scope.$watch('name', function (newValue) {
if (newValue >= 90) {
$scope.gpa = 4.0;
return;
}
if (newValue >= 85) {
$scope.gpa = 3.7;
return;
}
})
});
</script>
</body>
</html>