I want to use ng-view in angularjs. I created 3 html files in a folder. Two of them "view1.html" and "view2.html" are the pages that must be loaded inside ng-view. The third file is my main file which included the angularjs code as below:
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>
<script>
var angularModule = angular.module('demoApp', ['ngRoute']);
angularModule.config(['$routeProvider',
function ($routeProvider) {
$routeProvider
.when("/viewq", { controller: "testController", templateUrl: "/view1.html" })
.when('/vieww', { controller: 'testController', templateUrl: '/View2.html' })
.otherwise({ redirectTo: '/viewq' });
}]);
angularModule.controller('testController', function ($scope) {
$scope.systemData = [{ name: "Test", city: "Frankfort" },
{ name: "John", city: "New york" },
{ name: "Mike", city: "London" }
];
});
</script>
<body>
<div ng-app="demoApp">
<div ng-view></div>
</div>
</body>
The problem is the ng-view is commented out so I don't have the html files loaded.
NOTE: I received this error: XMLHttpRequest cannot load file:///C:/AngularJS/view1.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Does it mean it is not possible to write ng-view without hosting it? Could anyone give me a reference if it is the case?