如何使用Angularjs将JSON文件从本地计算机加载到变量?

时间:2017-05-17 05:46:42

标签: javascript angularjs json

我添加了用于将名为view.json的外部json文件添加到我的controller.js中的语法,但它没有提供所需的输出,或者我没有得到任何控制台中的响应。

$.require(['api-data/actions/product/view.json'], function(data) {
  $scope.data=data;console.log(data);

view.json

{ 

        'key':'{"name":"data[key]","id":"input_token","placeholder":"API token","description":"Enter the api_token","value":"","type":"text","required":"required"}',

        'filter': {

              'name':  '{"name":"data[filter][name]","id":"input_name","placeholder":"not mandatory","description":"leave blank   ","value":"","type":"text","required":""}',
    },

    'extra': {
        'pageJump': '{"name":"data[extra][pagejump]","placeholder":"First Name","description":"Enter page number[0,1,-1]","value":"0","type":"text","required":"required"}'
}

1 个答案:

答案 0 :(得分:2)

你可以这样做:

$http.get('path/file.json').success(function(data) {
   $scope.jsonData = data;

});