AngularJS Services for Ajax and Promises: Preparing the Example Project

For this chapter, I am going to make an addition to the angularjs folder. I need a data file for many of the examples in this chapter, and for this reason I added a file called productData.json to the angularjs folder, the content of which is shown in Listing 20-1.

Listing 20-1. The Contents of the productData.json File

[{ “name”: “Apples”, “category”: “Fruit”, “price”: 1.20, “expiry”: 10 },

{ “name”: “Bananas”, “category”: “Fruit”, “price”: 2.42, “expiry”: 7 },

{ “name”: “Pears”, “category”: “Fruit”, “price”: 2.02, “expiry”: 6 },

{ “name”: “Tuna”, “category”: “Fish”, “price”: 20.45, “expiry”: 3 },

{ “name”: “Salmon”, “category”: “Fish”, “price”: 17.93, “expiry”: 2 },

{ “name”: “Trout”, “category”: “Fish”, “price”: 12.93, “expiry”: 4 }]

This file contains some product information, similar to the data I used in earlier chapters, expressed in the JavaScript Object Notation (JSON) format, which I introduced in Chapter 5.

JSON is a language-independent way of expressing data that emerged from JavaScript but that has since taken on a life of its own and is supported by every major programming language—so much so that it has displaced other data formats, especially in web applications. XML used to be the data exchange format of choice (the X in Ajax stands for XML), but JSON has largely replaced it because it is more concise and easier for developers to read. As a bonus for web applications, JSON is easy to generate and parse with JavaScript, and AngularJS takes care of formatting and parsing automatically.

Source: Freeman Adam (2014), Pro AngularJS (Expert’s Voice in Web Development), Apress; 1st ed. edition.

Leave a Reply

Your email address will not be published. Required fields are marked *