Reputation: 6300
I use a directive (note: using jade template engine):
file-upload.uploadContainer(complete_function="set_value()")
the directive itself:
app.directive('fileUpload', function() {
return {
restrict: 'E',
scope: {
complete_function: "&completeFunction"
},
//the rest of the directive
This directive uses an UploadService which is angular service. I need to call complete_function in the controller when upload is finished.
uploadService.onUploadComplete(function(event) {
alert("OK");
console.log("upload successfully completed");
url = event.target.response;
console.log(url);
$scope.complete_function(url);
});
In the upload service I can see that url
(which is returning from the server) is valid. Then I proceed calling $scope.complete_function(url)
which looks like this:
$scope.set_value = function(url) {
console.log("called");
console.log(url);
I know this function gets called because I can see the log "called" (and I have debugged), so the whole chain works like a charm. However, for some reason, url
is undefined
in set_value()
...Why???
Does it have to do with isolated scopes and such?
How to do it correctly? I tried putting complete_function="set_value(**url**)
but this didn't help either.
Upvotes: 0
Views: 33
Reputation: 6300
I found the solution here: http://blog-it.hypoport.de/2013/11/06/passing-functions-to-angularjs-directives/
Basically need to provide a map of variable(s)...
Upvotes: 1