我创建了一个带有一些范围参数的自定义指令。我使用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" />
更新:在玩了一些之后我认为问题在于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>>"}]]
这是一个吸虫参考:http://plnkr.co/edit/dSkjP1Vkvwd4fVauiFqa?p=preview
答案 0 :(得分:2)
Angular 1.x摘要是围绕脏检查构建的。因此,通常绑定到函数并不是一个好主意,因为然后angular需要执行此函数以查看双向绑定值是否发生了变化。在这种情况下,getRequest()
函数将是有问题的函数。
如果将getRequest()
的结果绑定到主控制器中的变量,然后将此变量绑定到您的指令,那么您应该很高兴。