nemo_87
nemo_87

Reputation: 4791

Use JSON object in angular.js

Can I have some JSON object that is employes.json file for example:

{"employees":[
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}

And than use that object inside of a script where angular.js is? In other words how can I invoke predefined object in angular file and parse it?

Upvotes: 1

Views: 52

Answers (1)

T J
T J

Reputation: 43156

Just load it using $http service, for example

$http.get(url).then(function(response){
   // here response.data will be parsed JS object
});

Upvotes: 5

Related Questions