我有一個函數,它檢查userPermissions,它是一個名爲MyService的服務的一部分。我傳入的數組只有一個字符串。我面臨的問題是angular.forEach循環遍歷字符而不是整個字符串。請你指教?angular.forEach遍歷字符串數組
//服務變更
MyService.userHasPermission("['Read']")
//權限功能
function userHasPermission (permissions){
var found = false;
angular.forEach(permissions, function(expectedPermission, index){
if ($localStorage.userPermissions.indexOf(expectedPermission) >= 0){
found = true;
return;
}
});
return found;
};
您正在傳遞**字符串**而不是數組 – Weedoze
您需要傳遞數組。沒有字符串 –
沒錯。你需要做'MyService.userHasPermission(['Read'])' – Aron