angular.module('APP', ['ng']) .controller('wat_form',function($scope){ $scope.price=18; $scope.num=10; $scope.$watch('price',function(){ console.log('价格改变啦'+'---'+$scope.price); }) })
<!--数据双向绑定--> <form action="" ng-controller="wat_form"> <input type="text" ng-model="price"/><input type="text" ng-model="num"/> <p>总价:{{price*num}}</p> </form>
方向1:把Model数据绑定到View(Model=>View):只要模型数据此后再改变,View会同步改变。可以实现此绑定的方法:
1){{ 模型数据名 }}
2)ngBind、ngRepeat、ngShow...指令
方向2:把View中数据绑定到Model(View=>Model):只要View中的数据一改变(各种表单输入项),Model中的数据也会同步改变。可以实现此绑定的方法:
1) ngModal指令