$state.go('XXX') doesn't work in angularJS project -


  1. conditions: angularjs v1.0.3, angular-ui-router v0.2.10
  2. what want implement index html page dynamically forward login html, click login button, re-forward home page.
  3. due reputation not enough can not attach images. here attach demo code. 3.1: index.html

            <!-- stateprovider -->         <div ng-controller="democontroller">             <button ng-click="gotohomepage()">go home page</button>         </div>          <!-- load js -->         <script type="text/javascript" src="js/lib/jquery/jquery-2.1.3.js"></script>         <script type="text/javascript" src="js/lib/angular/angular.js"></script>         <script type="text/javascript" src="js/lib/angular/angular-route.js"></script>         <script type="text/javascript" src="js/lib/angular/angular-sanitize.js"></script>         <script type="text/javascript" src="js/lib/angular/angular-animate.js"></script>         <script type="text/javascript" src="js/lib/angular-ui/angular-ui-router.js"></script>          <script type="text/javascript" src="js/appdemo.js"></script>         <script type="text/javascript" src="js/service/demoservice.js"></script>         <script type="text/javascript" src="js/controller/democontroller.js"></script>      </body> 

    3.2: appdemo.js

    var app = angular.module("demo", ['ui.router']);  app.config(['$stateprovider', '$urlrouterprovider', function($stateprovider, $urlrouterprovider) {  //$urlrouterprovider.otherwise("/landing/dashboard"); $urlrouterprovider.otherwise("/login"); //$urlrouterprovider.when('/landing/influencers', '/landing/influencers/dashboard/market-view');  $stateprovider     .state('home', {         url: '/home',         templateurl: 'view/home.html',         controller: function(){             alert("123");         }     })      .state('login', {         url: '/login',         templateurl: 'view/login.html'     }); }]);  app.run(['$state', function ($state) {     alert("running...");     /*$state.transitionto('home');*/     $state.go('home'); }]); 

    3.3: democontroller.js

    app.controller('democontroller', function($scope, $state, demoservice){      $scope.gotohomepage = function(){         alert('aaa');         $state.go("home");     }  }); 

    when click 'go home page' button, nothing happened prompted message 'aaa' setted in gotohomepage function.

    any idea how forward home page correctly?

    any suggestion should highly appreciated.

you have old version angularjs not compatible angular-ui-roter.

updating angular script version 1.0.3 1.3.15 solve issue.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -