我是 angularjs 的新手,我正在对 Angular Controller 和模型进行简单的研究。 这是我的 javascript 模型代码。
var testApp = angular.module('testApp', []);
testApp.controller('testCtrl', function testCtrl($scope ,$http) {
$http.get('test.json').success(function ($data){
$scope.artists = $data;
});
});
网页已加载但出现异常。我在 Windows 7 中使用 firefox。
[Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 >.>(NS_ERROR_DOM_BAD_URI)" location: "file:///....// angular.min.js Line: 72"]
有人知道解决办法吗... 我不需要在服务器中制作它只需要使用本地机器..
最佳答案
您必须对 Angular Controller 语法做一个小的修正。
testApp = angular.module('testApp', []);
testApp.controller('testCtrl', function($scope, $http) {
$http.get('test.json').success(function($data) {
$scope.artists = $data;
});
});
关于javascript - json 文件未加载到浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25360674/