AngularJS触发输入类型编号的ng-change

时间:2018-11-05 16:14:57

标签: javascript angularjs

您好,我需要angularjs的帮助。

我要在输入类型编号输入字段上触发ng-change

 <input 
   ng-required="true"
   ng-change = "onChangePrePay()"
   type="number"
   ng-model="entry.team.prepaidEntriesNum"
  />

但仅当输入字段失去焦点时才触发变更。任何想法如何重写此行为。这是完全出乎意料的。

3 个答案:

答案 0 :(得分:3)

var app = angular.module('myApp',[]);
app.controller('ctrlMain',function($scope){
	 $scope.test = 23;	
   $scope.onChangePrePay = function(){
       alert('CHANGE');
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.9/angular.min.js"></script>

<body ng-app="myApp">
    <div ng-controller="ctrlMain">
        <input 
         ng-required="true"
         ng-OnChange = "onChangePrePay()" */change here in your code ng-OnChange instead of ng-change
         type="number"
         ng-model="test"
        />
    </div>
</body>

答案 1 :(得分:0)

使用 ng-change 而不是 ng-onchange

检查输入的触发器更改

答案 2 :(得分:0)

将“ ng-onchange”替换为“ ng-change”