0

I am parsing or reading a JSON file in my AngularApp. I want to create one template for each object inside the JSON file, and then load it with "previous" and "next" in my app.

So i have a JSON file, for example:

{
  "name": "test", 
  "objects":[
    {"one": "text here", "id" : "1" }, 
    {"two": "and text there", "id" : "2" }
  ]
}

So i want to create a template called "template1" and "template2".

I am starting with Angular, so i don't need a whole workaround, just where do i have to dig deeper?

  1. I created a controller for my app
  2. I've then created a jsonService which injectes the controller
  3. Now i have the JSON data

But what then? Do i have to create Directives? And how to load them into my main-page? With data-ng-view?

2 Answers 2

1

See this example which will give you an example of how you can iterate over json and render to html:

https://github.com/eu81273/angular.treeview/blob/master/angular.treeview.js

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

Comments

1

Thanks @Nikos for this possibility. I found a much simpler soultion:

I hard coded a ng-switch on="option" and then a ng-switch-when="optionN" in each div, so i can dynamically adjust one template to fit all options.

Comments

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.