【发布时间】:2016-02-01 14:30:28
【问题描述】:
我有一个以下格式的 Json 文件: json 文件的名称是 discover.json,路径是 json-files/discover.json
{"data": [
{"username": "aky123",
"name": "ajay"},
{"username": "sky123",
"name": "sanjay"}
]}
我的工厂是:
var myAppServices=angular.module('myAppServices',['ngResource']);
myAppServices.factory('ProfileData',['$resource', function($resource){
return $resource('/discover/:username.json', {}, {
query: {method: 'GET' , params: {username: 'json-files/discover' }, isArray: true }
});
}]);
App.js:
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/discover', {
templateUrl: 'partials/home-page.html',
controller: 'ProfileListCtrl'
}).
when('/discover/:username', {
templateUrl: 'partials/profile-detail.html',
controller: 'ProfileDetailCtrl'
})
在控制器中:
myAppControllers.controller('ProfileListCtrl',['$scope', 'ProfileData', '$timeout', function($scope, ProfileData, $timeout) {
$scope.profile=ProfileData.query();
console.log($scope.profile);
}]);
$scope.profile 无法从 JSON 文件中提取数据,我无法理解我的错误,所以请帮助我..
【问题讨论】:
-
"json 文件名是discover.json" 如果文件名是
discover.json那你为什么用'/discover/:username.json'?
标签: javascript angularjs json html