0

I have following code to setup the routing using Angular UI Router:

index.html

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="utf-8" />
    <title>AngularJS Routing</title>

    <script src="js/angular.js"></script>
    <script src="js/angular-ui-router.min.js"></script>
    <base href="/" />
    <script>
        'use strict'

        var myApp = angular.module('myApp', ['myApp.Controllers', 'ui.router']);

        var myAppControllers = angular.module('myApp.Controllers', []);

        myApp.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
            $stateProvider.state('view1', {
                url: '/view1',
                controller: 'Controller1',
                templateUrl: '/partials/view1.html'
            }).state('view2', {
                url: '/view2/:firstname/:lastname',
                controller: 'Controller2',
                resolve: {
                    names: function () {
                        return ['Misko', 'Voita', 'Brad'];
                    },
                },
                templateUrl: '/partials/view2.html'
            });
            $urlRouterProvider.otherwise('/view1'); 

            $locationProvider.html5Mode(true);
        });


        myAppControllers.controller('Controller1', function ($scope, $location, $state) {
            $scope.loadView2 = function () {                    
                $state.go('view2', {
                    firstname: $scope.firstname,
                    lastname: $scope.lastname
                });
            }
        });

        myAppControllers.controller('Controller2', function ($scope, $stateParams, names) {
            $scope.firstname = $stateParams.firstname;
            $scope.lastname = $stateParams.lastname;
            $scope.names = names;
        });

    </script>
</head>
<body>

    <ul class="menu">
        <li><a ui-sref="view1">View1</a></li>
        <li><a ui-sref="view2">View2</a></li>
    </ul>  
    </body>
</html>

I checked multiple times and I don't see any errors in console window of the chrome browser.

Can anyone help me to resolve this issue?

2
  • Are you launching this on a local server? Commented Feb 23, 2016 at 11:49
  • No I am using Visual Studio 2013 for running the application. Commented Feb 23, 2016 at 11:51

1 Answer 1

6

There's no ui-view directive in your html code. So the views have nowhere to render. You should add at least

<div ui-view></div>

to show the content of the views.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. It fixed the issue for me :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.