Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  135] [ 3]  / answers: 1 / hits: 103738  / 10 Years ago, thu, april 10, 2014, 12:00:00

Im playing with AngularJS for the first time, and im struggling to use ng-include for my headers and footer.



Here's my tree:



myApp
assets
- CSS
- js
- controllers
- vendor
- angular.js
- route.js
......
......
......
main.js
pages
- partials
- structure
header.html
navigation.html
footer.html
index.html
home.html


index.html:



<!DOCTYPE html>
<html ng-app=app>
<head>
<title>AngularJS Test</title>

<script src=/assets/js/vendor/angular.js></script>
<script src=/assets/js/vendor/route.js></script>
<script src=/assets/js/vendor/resource.js></script>
<script src=/assets/js/main.js></script>

</head>
<body>

<div ng-include src=partials/structure/header.url></div>
<div ng-include src=partials/structure/navigation.url></div>

<div id=view ng-view></div>

<div ng-include src=partials/structure/footer.url></div>
</body>
</html>


main.js



var app = angular.module(app, [ngResource, ngRoute]);


app.config(function($routeProvider) {

$routeProvider.when(/login, {
templateUrl: login.html,
controller: LoginController
});

$routeProvider.when(/home, {
templateUrl: home.html,
controller: HomeController
});

$routeProvider.otherwise({ redirectTo: '/home'});

});

app.controller(HomeController, function($scope) {
$scope.title = Home;
});


home.html



<div>
<p>Welcome to the {{ title }} Page</p>
</div>


When i go on the home.html page, my header, nav and footer are not appearing.


More From » html

 Answers
9

You're doing an include of header.url instead of header.html. It looks like you want to use literals in the src attribute, so you should wrap them in quotes, as was mentioned in the comments by @DRiFTy.



Change



 <div ng-include src=partials/structure/header.url></div>
<div ng-include src=partials/structure/navigation.url></div>

<div id=view ng-view></div>

<div ng-include src=partials/structure/footer.url></div>


to



 <div ng-include src='partials/structure/header.html'></div>
<div ng-include src='partials/structure/navigation.html'></div>

<div id=view ng-view></div>

<div ng-include src='partials/structure/footer.html'></div>


If this is not working, check the browser console if there are any 404's


[#71515] Wednesday, April 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aden

Total Points: 369
Total Questions: 100
Total Answers: 83

Location: Australia
Member since Tue, Oct 19, 2021
3 Years ago
;