Are angular views executed when the site is served from the local file system?

I am using angular to develop an application. I am developing my local file system on Windows. However, when I angular-route.js , whenever I click on index.html with my browser, it instead goes to index.html#/C:/ .

Defining my route:

 myApp.config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', {templateUrl: 'home.html', controller: 'HomeCtrl'}); } 

I think this makes the site break because /C:/ does not match any angular routes. Something went wrong? How to fix it?

+5
source share
2 answers

For routing and ajax (& more) to work correctly, start the local development server; Avoid using file:// for development, as browsers have different rules for it.

Tools like yeoman + generator-angular will automatically configure the grunt file with a server task that will start the node-connect server to serve your files locally.

You can do it with


Reply from comments: use a phone screensaver for a phone call. He does what I said, he starts the local server

+6
source

This will work.

 angular.module('MainModule', []).config(function($locationProvider, $routeProvider) { $locationProvider.hashPrefix("!"); $locationProvider.html5Mode(false); $routeProvider.when('/', {template: './js/templates/home.html', controller:HelloWorldCtrl}); $routeProvider.when('/other', {template: './js/templates/other.html'}); }); 

In the HTML index, you need to specify patterns:

 <script type="text/ng-template" src="./js/templates/home.html"></script> <script type="text/ng-template" src="./js/templates/other.html"></script> 
+3
source

All Articles