Q
Q
qwertyuih2017-03-04 15:56:54
JavaScript
qwertyuih, 2017-03-04 15:56:54

Angular how to solve problem with $http?

Just starting to learn angular and ran into a problem. Here is the client code:

angular.module('NewAppModule', []);
angular.module('NewAppModule')
.component('div', {
template: 
... ,
controller: [  '$scope', '$http',
function ($scope, $http){
$scope.url='app.json';
 $http({url: $scope.url, method:'GET'}).then(function(response) {
        console.log(response.data);
      });
}
]
});

app.json file:
{
'name' : 'Василий',
'number': '89201242536'
},
{
'name' : 'Николай',
'number': '89201265341'
},
{
'name' : 'Федор',
'number': '89031212434'
},
{
'name' : 'Всеволод',
'number': '89991201344'
},
{
'name' : 'Алексей',
'number': '89605663412'
},
{
'name' : 'Алена',
'number': '89144542106'
},
{
'name' : 'Ксюша',
'number': '89301612726'
},
{
'name' : 'Василиса',
'number': '89201441596'
},
{
'name' : 'Евгений',
'number': '89105722534'
},
{
'name' : 'Анатолий',
'number': '89208796712'
  }
]

The result is an error
SyntaxError: Unexpected token ' in JSON at position 6
.
What is my mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Baev, 2017-03-04
@qwertyuih

Valid JSON cannot have single quotes.

P
Programmir, 2017-03-04
@Programmir

can first figure out elementary json, and then climb into angular

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question