1

I need to make a post-type in my simple angular app... I have a json file with contacts

  {
    "contacts": [
      {
        "name": "Alf",
        "tel": [
          {
            "home": "0134567890"
          }
        ],
        "address": "1 A Road, A Town, A County, AB123CD",
        "email": "something@somehost.com"
      },
      {
        "name": "Andrew",
        "tel": [
          {
            "mobile": "0774567890"
          }
        ],
        "address": "1 A Road, A Town, A County, AB123CD",
        "email": "something@somehost.com"
      },
      {
        "name": "Zoe",
        "tel": [
          {
            "mobile": "07712456789"
          }
        ],
        "address": "1 A Road, A Town, A County, AB123CD",
        "email": "something@somehost.com"
      }
    ]
  }

I do not need an admin or db as I will be maintaining the site. Using the above i would like to click on a list item alf which will change the route and view to domain.com/alf or domain.com/contact/alf which will use the contact template view with alf's info (from the json)

Google searching has left me with only database/ server / admin tutorials. But my need is much simpler.

So in a nutshell — I need a route that accepts a url parameter which will load a view with data corresponding to the provided url parameter

Maxim Kuzmin
  • 2,574
  • 19
  • 24
Omar
  • 2,726
  • 2
  • 32
  • 65

1 Answers1

1

You can follow any tutorial from google you like replacing only one thing for yourself: data source. Normally data is loaded via REST api from database, but since you don't need to store data in db, you can use json-server for providing REST api based on your json file.

Maxim Kuzmin
  • 2,574
  • 19
  • 24
  • Thanks. I guess i was overthinking the simple part. Any favorite tutorials for this particular flow? – Omar Jan 16 '17 at 14:54
  • @Omar I am not sure that there is any tutorial about using `json-server` with AngularJS. I would recommend at first setup rest api for your file using `json-server` docs and then create app with angular routing https://docs.angularjs.org/tutorial/step_07 and for every route state call appropriate REST api endpoint https://docs.angularjs.org/tutorial/step_13 – Maxim Kuzmin Jan 16 '17 at 17:03
  • @Omar did it help? – Maxim Kuzmin Jul 29 '17 at 13:59