0
我有以下指令角指令解析變量起作用
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
所以我的問題是如何將變量/對象傳遞給這樣的函數?
我問我什麼時候應該用'&'呢? –
你不能使用=和功能 –
@MarcRasmussen當你想不加修改地綁定表達式時使用'&'。通常當你想調用無參數函數或任何其他表達式時使用它。 –