Cannot open Angular application using file protocol in Chrome.

Hi, I have a problem with angular and chrome, this is the code:

   var angularRoutingApp = angular.module('angularRoutingApp', ['ngRoute'])

   // Configuración de las rutas
   .config(function($routeProvider) 
   {

 $routeProvider
    .when('/', {
        templateUrl : 'pages/home.html',
        controller  : 'mainController'
    })
    .when('/artistas', {
        templateUrl : 'pages/artistas.html',
        controller  : 'artistasController'
    })
    .when('/login', {
        templateUrl : 'pages/login.html',
        controller  : 'loginController'
    })
    .otherwise({
        redirectTo: '/'
    });
    });

If I open index.html with Opera, Firefox or safary, I will not have any problems, but if I open it with Chorme, do not work with routerprovider and show me the error message in the console:

XMLHttpRequest cannot load the file: // localhost / Users / multivideo / Desktop / FTL- ​​Angular / pages / home.html. Cross-start requests are only supported for HTTP. index.html: 1

Error: A network error occurred.
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:72:206
at C (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:68:99)
at f (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:66:69)
at C (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:92:375)
at C (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:92:375)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:94:28
at h.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:102:293)
at h.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:100:50)
at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js:103:100) angular.js:9413
+4
source share
3 answers

Chrome uses a fairly strict policy with the same source. You can do two things:

1) file://. MAMP, - Apache - . Mac, , , Python http-,

$> python -m SimpleHTTPServer 8080

HTTP- 8080 , .

2) , , Chrome. , .

+7

-. file:// , , , ajax.

-, , angular . , , grunt serve. Moar https://docs.angularjs.org/tutorial/step_00

chrome XHR Google Chrome XMLHttpRequest URL-

+3

@Chris vCB php, ,

php -S localhost:8080

( :: )

0

Source: https://habr.com/ru/post/1539720/


All Articles