0

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"}'
}
1
  • 2
    Use $http get method: $http.get('pathto/view.json').then(function (res){}) Commented May 17, 2017 at 5:50

1 Answer 1

2

You Can do this way :

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

});
Sign up to request clarification or add additional context in comments.

3 Comments

both the methods are not working . in this project my requirement is i have to use requirejs and add the external json using that .. any idea can you help me to solve this?? you will get more information here . this is my actual code :-stackoverflow.com/questions/44015874/… @Anil Samal
The easiest way to do this is by using the requirejs json plugin. Here is an example:require(['json!someFile.json'], function(data){ })
:- i tried that first that also not working ..it returning the error in the console .it always shows the path wrong , but when i use $.get i'm getting the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.