4

I am trying to load data from local json file. I have provided the reference as shown below in screen shot. But when i run the app on localhost i get the error: 404 not found.

getMainCategory():Observable<MainCategory>{

  return this.http.get("./providers/mainCategory.json")
    .map(res=>res<MainCategory[]>(res.json().items))

}

Code Descript

8
  • check if your path is right Commented Nov 16, 2016 at 10:48
  • there's no screenshot Commented Nov 16, 2016 at 10:49
  • Please share the code if possible and missing the screenshot here Commented Nov 16, 2016 at 10:49
  • my bad.. let me edit question Commented Nov 16, 2016 at 10:49
  • hey try my answer, you just store data in variable and return that variable. Commented Nov 16, 2016 at 10:57

1 Answer 1

3

remember to inject $http. i have store json file in data folder

function loadBranch(){
        $http.get('data/branchList.json').success(function(response){

            vm.branchs = response;
        })
    }

branchList.json

[
  {
    "name":"sam"
  }
]

NOTE: check your json file path. i think your program couldn't able to get path

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

8 Comments

your code is not relevant to OP. Furthermore he has already injected http service. Its possibly his path problem
ya, i think his program couldn't able to get file
main problem is it cannot find the file on the path i provided.
It worked for me after i placed json file inside root folder www. Thanks for your suggestions..
so it is working when you put total path right ? if you put your mainCategory.json inside app folder then it will sure work, ex- http.get("mainCategory.json"). then no need to put absolute path.
|

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.