Reputation: 643
I am new to angularJs , just started with routes , i need some help to specify the html files inside templateUrl . Is it necessary that when specifying the html files inside templateUrl we are supposed to be inside localhost ? Can the html files present in the local directly work directly by specifying templateUrl :'first.html' ?
code : routing.js
var app = angular.module('RoutingApp',['ngRoute'])
app.config(['$routeProvider',function($routeProvider){
$routeProvider.
when('/',{
templateUrl: '/first.html',
}).
when('/about',{
template: 'About us',
}).
when('/contact',{
template: 'Contact us',
}).
otherwise({
redirectTo : '/'
});
}]);
My html file first.html is present inside D:\angularJs\first.html , so do i need to specify the directory also ?
main.html
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div ng-view></div>
<script src = "D://angularJs/angular.min.js"></script>
<script src= "D://angularJs/angular-route.min.js"></script>
<script src = "D://angularJs/routeController.js"></script>
Thank you
Upvotes: 1
Views: 1943
Reputation: 51
Angular pulls out templates (ui-router at least) from server based on your routes.js/app.js file location. So you can use relative paths for a templateUrl property. Better off, place all your templates in folder like ./templates.
Upvotes: 1