这个指令会在表单输入发生变化时计算给定表达式的值。因为要处理表单输入,这个指令要和ngModel联合起来使用。
<div ng-controller="EquationController"><input type="text"
ng-model="equation.x"
ng-change="change()" /> <code>{{ equation.output }}</code>
</div>
angular.module('myApp',[]).controller('EquationController',function($scope) {
$scope.equation = {}; $scope.change = function() {
$scope.equation.output = parseInt($scope.equation.x) + 2;
};});