我正在尝试从url获取json文件并将其显示在离子状态,但它无法正常工作 .i希望在页面加载时显示json数据,当我将数据分配给varable时 手动它的工作原理,但当我尝试从一个网址,它不加载attall。
contoller.js class。
angular.module('starter.controllers', [])
.controller('ChatsCtrl',function($scope,$http) {
$scope.data = {};
$scope.chats = $http.get('localhost/angl/file.json').success(function(res)){
return res.data;
});
})
当我像这样直接尝试时,它可以工作
第二个controller.js类
angular.module('starter.controllers', [])
.controller('ChatsCtrl',function($scope) {
$scope.chats=[{
id: 0,
name: 'Ben Sparrow',
lastText: 'You on your way?',
face: 'img/ben.png'
}, {
id: 1,
name: 'Max Lynx',
lastText: 'Hey, it\'s me',
face: 'img/max.png'
}, {
id: 2,
name: 'Adam Bradleyson',
lastText: 'I should buy a boat',
face: 'img/adam.jpg'
}, {
id: 3,
name: 'Perry Governor',
lastText: 'Look at my mukluks!',
face: 'img/perry.png'
}, {
id: 4,
name: 'Mike Harrington',
lastText: 'This is wicked good ice cream.',
face: 'img/mike.png'
}];
})
但我想从url帮助我阅读
这是我收到的错误消息
Failed to load resource: net::ERR_EMPTY_RESPONSE (23:37:59:154 | error, network)
at http://localhost:8383/someApp/cordova.js
Uncaught SyntaxError: Unexpected token ) (23:37:59:504 | error, javascript)
at www/js/controllers.js:7
Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module starter.controllers due to:
Error: [$injector:nomod] Module 'starter.controllers' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.3/$injector/nomod?p0=starter.controllers
答案 0 :(得分:0)
$http.get('localhost/angl/file.json').success(function(res)){
$scope.chats = res.data
});