私は入力に対して何らかのチェックを行い、何らかの遅延を伴って保存してストレスを与えないようにするコンポーネントを作成しようとしていますあまりにも多くのデータベース。バインディングとして受け取ったコントローラ内の関数を呼び出す方法
これは私がソートできない部分の簡略化されたコードです。 問題は、updateFunctionが未定義であることです。どうすればアクセスできますか?
var app = angular.module('myApp', []);
app.controller('mainCtrl', function($scope) {
$scope.value = 2;
});
app.component('saveDelay', {
restrict: 'E',
template: '<input type="text" ng-model="inputValue" />',
bindings: {
inputValue: '=',
updateFunction: '&'
},
controller: function($scope) {
var saveTimer;
$scope.$watch('inputValue',
function(newValue, oldValue) {
if (newValue === oldValue)
return;
clearTimeout(saveTimer);
saveTimer = setTimeout(updateFunction, 1000);
}
);
}
});
HTML:
<div ng-app="myApp" ng-controller="mainCtrl">
<save-delay input-value="value" update-function="Alert(value)" />
</div>
ここでは、それはあなたのコントローラのプロパティではありませんので、あなたのコードupdateFunction
で私のjsfiddle https://jsfiddle.net/fph33y20/