Angular 指令解析变量函数

Angular directive parsing variables to function

我有以下指令

    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);
            }
        }
    };
}]);

该指令(如您所见)接受一个函数,该函数位于以下控制器中:

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>

该函数有效并被正确调用,但是我用它解析的变量始终是 undefined

所以我的问题是如何将变量/对象传递给这样的函数?

将指令参数绑定更改为 =:

completeCallback: '='

更改 HTML 以引用函数(没有 ()):

complete-callback="frCTRL.completeUser"

然后你就可以开始了。