1

simple angular ui example not working. There are no errors in console.

Here is the example:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <title>Home</title>
        </head>

        <script>
            window.onload = function ()
            {
                var myApp = angular.module('myApp', ['ui.router']);

                myApp.controller('MainCtrl', function ($scope) {
                });

                myApp.config(function ($stateProvider, $urlRouterProvider) {

                    // default route
                    $urlRouterProvider.otherwise("/first");

                    // ui router states
                    $stateProvider
                            .state('first', {
                                url: "/first",
                                views: {
                                    header: {
                                        template: '<h1>First header</h1>',
                                        controller: function ($scope) {
                                        }
                                    },
                                    content: {
                                        template: '<p>First content</>',
                                        controller: function ($scope) {
                                        }
                                    },
                                    footer: {
                                        template: '<div>First footer</div>',
                                        controller: function ($scope) {
                                        }
                                    }
                                }
                            });
                });
            }
        </script>
        <body ng-controller="MainCtrl">
            <ul>
                <li><a href="#" ui-sref="first">First</a></li>
                <li><a href="#" ui-sref="second">Second</a></li>
            </ul>    

            <div ui-view="header"></div>
            <div ui-view="content"></div>
            <div ui-view="footer"></div>

            <!-- Bootstrap core JavaScript + Angular Js
      ================================================== -->
            <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js"></script>   
        </body>
    </html>

I have included all the resources using external cdn. The template content written in angular is not displayed. I am I doing it correctly?

Here is the plunker: Plunker

2 Answers 2

1

You have not mentioned app name anywhere in the view.

<html lang="en" ng-app="myApp">

Here is the working Plunker

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

1 Comment

I have used ui router only to load common header and footer using angluar. I am not sure it is the right approach?? Of course header would have login/logout based on login status
1

Remove window.onload. Make sure the angular and ui-router scripts are loaded before your script. And add the missing ng-app="myApp" to the html element.

Plunkr: http://plnkr.co/edit/XaR3KD2hJ1jOVZ2mWi5H?p=preview

4 Comments

what is different from my answer?
Not much, except some more explanations. Why do you think it should be different? There aren't so many ways of fixing the OP's code. We just wrote our answer concurrently.
Was about to say that "concurrently"
I have used ui router only to load common header and footer using angluar. I am not sure it is the right approach?? Of course header would have login/logout based on login status

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.