<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
</head>
<body ng-app="Mapp" ng-controller="Mctrl">
标题:<input type="text" ng-model="title" id="" value="" />
<br />{{error}}
<script>
var m = angular.module("Mapp", [])
m.controller("Mctrl", function($scope,$filter) {
$scope.title="";
//监视器,监视title的长度
//a是实际的title
//b是上一次的值(b与a一样时不会触发)
$scope.$watch("title",function(a,b){
$scope.error = a.length>3?'标题长度不可超过三位':'';
alert(b)
})
})
</script>
</body>
</html>
08-26