http://jsfiddle.net/ntszE/
<input type="text" placeholder="0" ng-model="deposit" value="4" />€ alert('begin test'); alert($scope.deposit); alert('end test');
在将输入值绑定到范围变量时,我做错了什么?
解决方法
您必须访问控制器中的$scope.查看你的小提琴
http://jsfiddle.net/lpiepiora/ntszE/2/的修改
基本上你必须定义一个控制器
function MyCtrl($scope) { $scope.deposit = 4; $scope.showValue = function() { alert($scope.deposit); }; };
然后使用ng-controller指令绑定它:ng-controller =“MyCtrl”.