在下面的示例中,我必须在角色中使用服务如何使用服务并从那里返回数组值
例子 :
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider, $rootScope) {
$urlRouterProvider.otherwise('signin');
$stateProvider.state('site', {
'abstract': true,
resolve: {
authorize: ['authorization', function (authorization) {
return authorization.authorize();
}, ]
}
})
.state('signin', {
parent: 'site',
url: '/signin',
data: {
roles: (function () {
//principal.GetRoles(); --> in the below line i am returning hardcoded array value but i have take that array value from below principle factory
return ['Dev','Admin'];
})()
},
views: {
'': { templateUrl: '/signin.html' },
'content@': {
templateUrl: '/index.html',
controller: 'SigninCtrl'
}
},
})}
])
服务/工厂:-从这里我需要到return array
上面的自定义对象数据->signin
状态内部的角色
下面的例子: -
.factory('principal', ['$q', '$http', '$timeout', '$cookieStore', '$cookies', function ($q, $http, $timeout, $cookieStore, $cookies) {
var _identity = undefined,
_authenticated = false;
return {
isIdentityResolved: function () {
return angular.isDefined(_identity);
},
isAuthenticated: function () {
return _authenticated;
},
RedirectUrl: function (absUrl) {
$cookieStore.put('RedirectUrl', absUrl);
return true;
},
GetRoles: function () {
return ['Dev','Admin']
},
}
])