Answer the question
In order to leave comments, you need to log in
How to determine why a function is called twice in a controller?
I have a controller:
<div ng-controller="Main">
<widget autoupdate="true" exec="myconsole"/>
<widget />
<widget />
<widget />
<widget />
<widge/>
</div>
function Main($scope){
$scope.myconsole = function(val) {
console.log(val);
}
}
const widgetsComponent = {
bindings: {
'autoupdate': '@',
'exec': '=',
},
template: require('./view/blocks/widgets.html'),
};
<div>
{{ $ctrl.autoupdate ? $ctrl.exec(1) : 0 }}
..
</div>
<div ng-controller="Main">
<widget autoupdate="true" exec="myconsole"/>
<widget />
<widget />
<widget />
<widget autoupdate="true" exec="myconsole"/>
</div>
Answer the question
In order to leave comments, you need to log in
Because {{ $ctrl.autoupdate ? $ctrl.exec(1) : 0 }} will be executed on each sneeze of the $digest loop.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question