in meiner App habe ich viele verschiedene USER ROLE's. Und auf einem Staat muss ich verschiedene Rollen einstellen. Bellow Code, mit nur einer Benutzerrolle, arbeitet okBenutzerrolle auf UI-STATE
.state('distributor-dashboard', {
url: '/distributor-dashboard',
templateUrl: 'assets/html_templates/distributor-dashboard/distributor-dashboard.html',
controller: 'distributorDashboardCtrl',
authentication: {role: admin}
})
Aber, wenn ich versuche, eine andere Rolle hinzuzufügen, sie don‘Arbeit hier ist Beispiel
.state('distributor-dashboard', {
url: '/distributor-dashboard',
templateUrl: 'assets/html_templates/distributor-dashboard/distributor-dashboard.html',
controller: 'distributorDashboardCtrl',
authentication: {role: ["admin" || "user"]}
})
Hier ist, wo ich Benutzerrolle überprüfen
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
$rootScope.previousState = fromState.name;
var auth = authService.authentication.isAuth;
if (toState.name !== "login" && toState.name !== "signup" && toState.name !== "resset-password" && toState.name !== "new-password" && toState.name !== "account-activation" && auth === false) {
event.preventDefault();
$state.go('login', {});
}
var role = authService.authentication.role;
if (toState.authentication !== undefined && toState.authentication.role !== role) {
event.preventDefault();
$state.go('login', {});
}
}
Thnx.
in Ihrem zweiten Code, Sie zurückgeben 'Array', stellen Sie sicher, dass die gleiche von Service zurückgegeben wird, oder ändern Sie, ' Authentifizierung: {Rolle: ("admin"! = undefiniert? "admin": "user")} ' – Sravan
thnx, aber das funktioniert nicht ... – Arter
Fehler bekommen ?, nur' console.log (toState.authentication) 'und prüfen, was ist cming – Sravan