在angular.js中使用JSON对象

时间:2021-03-09 19:41:29

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

我可以使用一些雇员,例如:hirees.json文件的JSON对象:

{"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?

而且在angular.js所在的脚本中使用该对象?换句话说,如何在angular文件中调用预定义对象并解析它?

1 个解决方案

#1


5  

Just load it using $http service, for example

例如,只需使用$ http服务加载它

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

#1


5  

Just load it using $http service, for example

例如,只需使用$ http服务加载它

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