0
我得到這個錯誤: TypeError:無法讀取屬性'preventDefault'未定義在Scope。$ scope.dispatchAction。
我找不出什麼問題,請你幫我一下?謝謝。
---- ----模板
$templateCache.put("template/dropdown-user.html",
'<ul class="dropdown-menu dropdown-user">'+
'<li ng-repeat-start="item in items">'+
"<a ng-click=\"click(item,$event)\" ng-href=\"{{item.link}}\"><i class=\"fa fa-{{item.icon}} fa-fw\"></i> {{item.label}}</a>"+
'</li>'+
"<li ng-repeat-end class=\"divider\" ng-if=\"item.isDivider\"></li>"+
'</ul>'
);
---指令---
.directive('navbarMenuUserItem',[function(){
return {
restrict: 'E',
templateUrl: 'template/dropdown-user.html',
replace: true,
scope:{
items: '=',
click: '&itemClick'
}
}
}])
--- HTML-- -
<navbar-menu-user-item item-click="dispatchAction(obj,event)" items="usermenu"></navbar-menu-user-item>
控制器*
app.controller('dashboardCtrl',
['$scope','$sanitize','$log','$location','dashboardService','AuthService',
function($scope, $sanitize, $log, $location, dashboard,AuthService){
$scope.messages = dashboard.getMessages();
$scope.usermenu = dashboard.getUserMenu();
$scope.sidebarmenu = dashboard.getSidebar();
$scope.logout = function(){
AuthService.logout();
$location.path('/');
};
$scope.dispatchAction = function(obj,event){
event.preventDefault();
console.log(obj);
};
}
]);
@KhanhTO,我剛加了$,但還是沒有運氣,謝謝。 –
您使用錯誤的語法來調用範圍函數綁定。在模板dropdown-user.html –
中點擊「 maurycy