2

[![

/* app.js */

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

model.config(function($stateProvider, $urlRouterProvider){

	$urlRouterProvider.otherwise('/home');
	
	$stateProvider
	
	.state('home',{
		url: '/home',
		templateUrl: 'view/home.html',
		controller: 'homeController'
	})

});

/* home.js */

model.controller('homeController',function($scope){

});
<!-- index.html -->

<!DOCTYPE html>
<html>
	<head>
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<script type="text/javascript" src="js/angular.min.js" ></script>
		<script type="text/javascript" src="js/angular-ui-router.min.js" ></script>
		<script type="text/javascript" src="controller/app.js" ></script>
		<script type="text/javascript" src="controller/home.js" ></script>
	</head>
<body ng-app="app">
<header>Jayesh Shelar</header>
<div id="view" ui-view> </div>

</body>
</html>

]1]1HI

I am getting error as "angular.min.js:103 XMLHttpRequest cannot load file Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."

3
  • Use webserver. Don't use file:/// protocol. Commented Apr 26, 2016 at 6:22
  • do i need to use webserver like tomcat, wamp etc to run angularjs ? Commented Apr 26, 2016 at 6:33
  • 1
    Yes. However it's not about Angular, it's about stricter web-security policies browsers impose these days. You need to use http:// protocol. Any webserver will work for your purpose: Apache, Tomcat, or very simple npm packages like lite-server or even simple python server run from terminal python -m SimpleHTTPServer 3000. Commented Apr 26, 2016 at 6:51

2 Answers 2

6

You can do npm install http-server -g and start the server in your project folder by using http-server command.

Sign up to request clarification or add additional context in comments.

Comments

1

Re-start Chrome with the command line option --allow-file-access-from-files

For security reasons, you might want to have a separate shortcut to start Chrome for local debugging with that command line option.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.