0
我已經創建了一個自定義指令,它需要一些範圍參數。我使用watchGroup傳入參數更改。這是指令的一部分:
scope.$watchGroup(['repairer', 'initial'], function() {
if (scope.initial) {
scope.Repairer = scope.initial;
} else {
scope.Repairer = scope.repairer;
}
console.log('scope.Repairer value:', scope.Repairer);
if (scope.Repairer) {
console.log('wooohoo calling scriptservice');
scriptingService.getScript(scope.request).then(function(scripts) {
scope.scripts = scripts;
});
} else {
scope.scripts = null;
}
});
我使用的指令,因爲在我的頁面如下:
<scripting repairer="repairer" request="getRequest(repairer,initial)" initial="initial" />
UPDATE:張望了一下後打我越覺得這個問題是調用getRequest方法不是watchGroup聲明。
爲什麼我現在收到此錯誤:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"}}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}],[{"msg":"fn: regularInterceptedExpression","newVal":{"allocationProcess":"direct","allocationSource":"internal","brand":"popie","includeSegment":false,"relationship":"lol","ruralSearch":true,"state":"VIC"},"oldVal":"<<already seen>>"}]]
這裏是一個plunker裁判:http://plnkr.co/edit/dSkjP1Vkvwd4fVauiFqa?p=preview
問題是結果取決於修理工。當我選擇不同的修理工時,我希望getRequest返回不同的請求。 –
在這種情況下,我會建議您將'getRequest'函數作爲回調傳遞給您的指令,並在更改時使用新的repairer值調用它。大致這將看起來像這樣:http://plnkr.co/edit/cUpMl3Lj8RCMMZIdAzbY?p=preview – boyomarinov
真棒老兄謝謝 –