I have a json file in the following format: the json file name is .json detection and the path is json-files / discover.json
{"data": [
{"username": "aky123",
"name": "ajay"},
{"username": "sky123",
"name": "sanjay"}
]}
my factory:
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'
})
and in the controller:
myAppControllers.controller('ProfileListCtrl',['$scope', 'ProfileData', '$timeout', function($scope, ProfileData, $timeout) {
$scope.profile=ProfileData.query();
console.log($scope.profile);
}]);
$ scope.profile cannot extract data from a JSON file, I cannot understand my error here, so please help me ..