我一直在努力解决这个问题几个小时,我不确定我做错了什么。
我有以下指令:
module.directive('userFullTextSearchSelect', [function () {
return {
restrict: 'A',
scope: {},
templateUrl: 'views/users/user.full.text.search.select.html',
controller: 'UserFullTextSearchSelectController',
controllerAs: 'ctrl',
bindToController: {
userChange: '&'
}
};
}]);
和控制器:
module.controller('UserFullTextSearchSelectController', ['$q', 'UserFactory',
function ($q, UserFactory) {
var self = this;
self.itemChanged = itemChanged;
function itemChanged(user) {
console.log('itemchanged' + user);
self.change = user ? user.UserID.ID : null;
if (self.change !== self.previousChange)
self.userChange(user);
self.previousChange = self.change;
};
}]);
});
调用self.userChange时,会调用下面父视图中的函数,但参数未定义 - 我哪里错了?
<div user-full-text-search-select user-change="userChanged(user)"></div>
function userChanged(user) { <----------- user is undefined
console.log('user' + user);
self.detail.filter.UserID = user ? user.UserID.ID : null;
getData(1);
};
谢谢,