angularjs - seems like $state.go has no effect on my app, it does nothing at all -


Hi friends I have tried to use the angular UI router but it seems that I can not get any $$ It does not do anything just use State.go.

My config:

  muApp.config (['$ stateProvider', '$ locationProvider', '$ urlRouterProvider' ($ StateProvider, $ locationProvider, $ urlRouterProvider) { $ UrlRouterProvider.otherwise ('/ home'); $ stateProvider. State ('home', {url: '/ home', templateUrl: 'templates / login.html' state ('login', {url: 'homectrl'} 'Template', {url: '/ test', templateUrl: 'templates / o.html', administrator: 'testCtrl'}) '/ login', template url: 'templates / login', administrator: ' LoginCtrl '}); if (window.history & window.history.pushState) {$ locationProvider.html5Mode (true);}}]));  

And when I try to use $ state.go ('login') nothing happens for example MuApp.factory ('Auth', ['$ RootScope', '$ cookies', 'restangular', '$ state', function ($ Rootscope, cookies, restangelular, $ state)

{Function getCurrentUser () {if we have already met the user so that there is no need to check with the server, then $ rootScope.user;} var login_needed = false; / / If the user does not have this cookie, then this means that (! $ Cookies.userid) Login_needed = true;} // If he has a cookie then ask the server if everything is fine with this user [and we Get some information about Ray Usage! If (Login_needed) {restonular.one ('user', $ cookies.userid) .get (). Then (function (user) {// user data in our attitude $ RootScope.user = user; return user;}, function () {// We were unsuccessful, probably the user was not authenticated TODO: will not we warn the user about their working account? Login_needed = true;} );} If (login_needed) {console.log ('first'); $ State.go ('login'); Console.log ('after'); Return tap; }} Return {getCurrentUser: function () {getCurrentUser (); }}

It prints over the console:

 before   

and url / home or / test Or whatever was before.

I also used the $ State. In the controller and even nothing else in app.run (). I also tried $ state.transitionTo ('login') but it does nothing :( (eg $ state.go

From:

  $ rootScope. $ ('$ StateChangeStart', function (event, toState, toParam, fromState, fromParams) {console.log ('$ stateChangeStart In '); if (toState.name! =' Login ') {event.preventDefault (); Auth.getCurrentUser ();}});  

The problem is fixed :) It looks like event.preventDefault () can not change the URL


Comments