$ state.go ('XXX') not working in angularJS project

  • Conditions: AngularJS V1.0.3, Angular-UI-Router V0.2.10
  • What I want to implement is the html index page dynamically redirected to enter the html, then click the login button, it will redirect to the home page.
  • Not enough due to my reputation, so I cannot attach images. I will attach my demo code here. 3.1: index.html       

            <!-- StateProvider -->
            <div ng-controller="demoController">
                <button ng-click="goToHomePage()">Go To Home Page</button>
            </div>
    
            <!-- Load extra 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 I click the Go to Home button, nothing happened, but the AAA message appeared which was set in the goToHomePage function.

    Any idea how to get to the homepage correctly?

    Any suggestion should be highly appreciated.

+3


source to share


1 answer


Your version is too old angularjs

and not compatible with angular-ui-roter

.



Updating the angular script version from 1.0.3

to 1.3.15

will solve your problem.

+1


source