Javascript AngularJS 1.5当模板组件内部发生更改时,如何获取事件;s
示例-我有一些输入的表单,如:Javascript AngularJS 1.5当模板组件内部发生更改时,如何获取事件;s,javascript,angularjs,Javascript,Angularjs,示例-我有一些输入的表单,如: <form> <input type="text" ng-model="$ctrl.inputText"> <input type="number" ng-model="$ctrl.inputNumber"> </form> 我的应用程序基于组件,因此在控制器中,当输入中的数据发生更改时,我需要调用事件。 方法$onChanges仅在绑定变量将被更改时有效,并且在模板内部发生更改时不受影响。您只需使用 var
<form>
<input type="text" ng-model="$ctrl.inputText">
<input type="number" ng-model="$ctrl.inputNumber">
</form>
我的应用程序基于组件,因此在控制器中,当输入中的数据发生更改时,我需要调用事件。
方法$onChanges仅在绑定变量将被更改时有效,并且在模板内部发生更改时不受影响。您只需使用
var myComponent={
作用域:{},
绑定:{},
控制器:函数(){
this.inputText=“boo”;
这个.inputNumber=666;
this.changeEvent=函数(val){
console.log(“更改事件”+val);
}
},
模板:[
'',
'',
'',
''
].加入(“”)
};
角度模块('myApp',[]);
有棱角的
.module('myApp')
.component('myComponent',myComponent)代码>
在控制器中:
$scope.$watch("myForm.$dirty", function() {
$scope.myForm.$setPristine();
});
Html:
您的控制器看起来像什么?我的控制器现在是空的是的,但如果我需要跟踪所有表单,是否可能?
<form name="myForm">
<input type="text" ng-model="$ctrl.inputText">
<input type="number" ng-model="$ctrl.inputNumber">
</form>