0

I have the following directive

    feedBackModule.directive("responseCollection", ['deviceDetector', function (deviceDetector) {
    return {
        restrict: "E",
        templateUrl: 'js/modules/Feedback/directives/feedbackResponse/collection.html',
        scope: {
            collections: '=',
            completeCallback: '&'
        },
        link: function (scope, element, attr) {
            scope.endCollection = function () {
                scope.completeCallback(scope.collections);
            }
        }
    };
}]);

This directive (as you can see) takes a function which is placed in the following controller:

feedBackModule.controller('FeedbackResponseController', ['$state', 'Query', 'feedbackSkillService', 'feedbackFactory', 'feedbackResponseService', function ($state, Query, SkillFactory, feedbackFactory, feedbackResponseService) {
    var num_users = null;
    var user_index = 0;
    this.activeUser = null;
    this.final = false;
    this.feedback = feedbackResponseService.getFeedback();

    this.completeUser = function (collections) {
        this.activeUser.start = false;
        if(user_index < (num_users-1)){
            user_index++;
            this.activeUser = this.feedback.feedback_has_target_users[user_index];
        }
        else
        {
            this.final = true;
        }
    }
}]);

Html:

<response-collection complete-callback="frCTRL.completeUser()" collections="frCTRL.feedback.feedback_collections" ng-if="frCTRL.activeUser.start && !frCTRL.final"></response-collection>

The function works and is correctly called however the variable i parse with it is always undefined

So my question is how can i pass a variable / object to a function like this?

1 Answer 1

1

Change the directive parameter binding to =:

completeCallback: '='

Change the HTML to reference the function (without ()):

complete-callback="frCTRL.completeUser"

And you'll be good to go.

Sign up to request clarification or add additional context in comments.

4 Comments

My i ask when i should use '&' then?
you can not use = with function
@MarcRasmussen You use & when you want to bind an expression without modifications. Usually you use it when you want to invoke parameterless functions, or any other expressions.
@RIYAJKHAN That's not true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.