你根本就提上了場的控制,如果你想這樣做,爲每個單獨的領域,或者你可以把它放在模板本身如果函數將每個字段相同,指定一個函數運行後在ng-mouseOver中。像這樣:
formlyConfigProvider.setWrapper([
{
template: [
'editorEnabled: {{to.editorEnabled}}',
'<div ng-mouseover="to.editorEnabled=true; Update()" ng-mouseleave="to.editorEnabled=false; Update()">',
'<formly-transclude></formly-transclude>',
'</div>'
].join(' '),
controller: function($scope) {
$scope.Update = function() {
//Code to run when value changes
}
}
}
]);
如果您是在每個單獨領域做(如果你將要調用的函數將是每個字段不同),你會做:
vm.fields = [
{
key: 'textField1',
type: 'input',
templateOptions: {
label: 'Input1',
type: 'text',
value:vm.model.textField1,
editorEnabled: false
},
controller: function($scope) {
$scope.Run = function() {
alert('Changed!');
}
}
},