我想从服务中检测当前状态的名称。
问题:$state.current.name
返回null。
app.factory('rootUserService', ['$http', '$state', '$stateParams', '$rootScope', '$q', 'socketFactory', function($http, $state, $stateParams, $rootScope, $q, socketFactory) {
return {
guestOrNot: function(res) {
if ( res._id === 'someid' ) {
$rootScope.isGuest = true;
}
else {
$rootScope.isGuest = false;
// if current state = app.landing, do something.
console.log($state) // current.name field is 'app.landing'
console.log($state.current) // name field is empty
console.log($state.includes('app.landing')) // returns false no matter what.
};
}
}]);
console.log($ state)返回以下内容:
console.log($ state.current)返回以下内容