Preface: @MaximShoustin's answer is correct. However, I'm not sure it addresses some of the other problems with what's going on here.
Also, I don't want this to sound condescending at all, it's just constructive criticism. Take it or leave it.
The wiring up of callbacks should probably be done by your controller, rather than your view.
Why?
- It's harder to test the controller if the callback is wired by your view.
- It's "business logic".
- The view should just be concerned with displaying things and wiring up events.
It looks like you're trying to wire up business logic in your view. In other words you're saying "when you click this thing, call this function, then call this other function when you're done".
$scope.doSomething = function($index, event) {
//do stuff
$scope.generate();
};
$scope.generate = function (){
//more stuff.
};
Why are you passing controller-scoped variables into a function that was passed into a function by an evaluated expression in an event binding? Seems convoluted.
I'm speaking specifically of this line:
callback($scope, $http);
What's the purpose here? Is it that "generate" is going to be different for each event? Why do you have to pass $scope and $http into it? You should have access to those throughout your controller function.
It seems like you're trying to do something crazy here. Perhaps I don't understand the problem you're trying to solve.