简体   繁体   中英

How to load a JSON file from local machine to a variable using Angularjs?

I'm adding the syntax I'm using to add the external json file named view.json into my controller.js, but it is not giving the desired output or I'm not getting any response in console.

$.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"}'
}

You Can do this way :

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

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM