Vault Dweller
Vault Dweller

Reputation: 135

Angular ng-include

I am just learning angular.js here is my first 'hello world' script. I am trying to use ng-include to include a navbar from local file /templates/nav.html. I am following a tutorial and cant figure out why its not working.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Hello World</title>

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
   <link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
<body ng-app="app">
    <header ng-include src="'templates/nav.html'">
    </header>
    <div ui-view></div>
    <section>
    </section>
    <footer>
    </footer>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/app.js"></script>

</body>

this is my js/app.js file:

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

templates/nav.html is simply the default bootstrap navbar. what am i doing wrong?

Upvotes: 0

Views: 315

Answers (2)

mofojed
mofojed

Reputation: 1393

You need to include your js/app.js file as a script - right now there's no angular app being instantiated.

Add this as the last script to be included:

<script src="js/app.js"></script>

Upvotes: 2

Jonathan
Jonathan

Reputation: 1755

It should be:

    <div ng-include="'templates/nav.html'"></div>

And put the header tag inside your nav.html.

Upvotes: 2

Related Questions