0

I am trying to load a template with ui-router in angular js. These are my html and js files.

   <!DOCTYPE html>
<html>
    <head>     
        <title>AngularJS UI Routing</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
    </head>
    <body ng-app="app">
        <a href='#/first-msg'>link</a>
        <div ui-view></div>

        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.4.2/angular-ui-router.js"></script>
        <script src="application.js"></script>
    </body>

</html>

application.js

   var app = angular.module('app', []);
app.config(['$stateProvider', function($stateProvider) {
    $stateProvider.state('firstMessage', {
        url: '/first-msg',
        template: '<strong>hi this is 1st message</strong>'
    });
}])
1
  • And so what's happening? Commented Mar 21, 2017 at 12:54

1 Answer 1

2

You need to inject ui.router to the module,

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

DEMO

var app = angular.module('app', ['ui.router']);
app.config(['$stateProvider', function($stateProvider) {
    $stateProvider.state('firstMessage', {
        url: '/first-msg',
        template: '<strong>hi this is 1st message</strong>'
    });
}])
<!DOCTYPE html>
<html>
    <head>     
        <title>AngularJS UI Routing</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
</head>
 <body ng-app="app">
<a href='#/first-msg'>link</a>
<div ui-view></div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.4.2/angular-ui-router.js"></script>
</body>
</html>

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

1 Comment

Can you tell me about this error. html is same and home.html contains <strong>{{message}}</strong> var app = angular.module('app', ['ui.router']); app.config(['$stateProvider', function($stateProvider) { $stateProvider.state('firstMessage', { url: '/first-msg', templateUrl: 'home.html', controller: 'homeCtrl' }); }]); app.controller("homeCtrl", ['$scope', function($scope) { $scope.message = "This is home"; }]);

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.