Real apps generally talk to real servers. Mobile apps and the emerging Chrome desktop apps may be exceptions, but for everything else, whether you want persistence in the cloud or real-time interactions with other users, you probably want your app to talk to a server.
For this, Angular provides a service called $http. It has an extensive list of abstractions that make it easier to talk to servers. It supports vanilla HTTP, JSONP, and CORS. It includes security provisions to protect from both JSON vulnerabilities and XSRF. It lets you easily transform the request and response data, and it even implements simple caching.
Let’s say we want to retrieve products for our shopping site from a server instead of from our silly in-memory mocks. As its just an overview of how to communicate with servers, so let’s imagine that we’ve created a service that will return a list of products as JSON when you make a query to /products.
Given a response that looks like this:
[
{
“id”: 0,
“title”: “Paint pots”,
“description”: “Pots full of paint”,
“price”: 3.95
},
{
“id”: 1,
“title”: “Polka dots”,
“description”: “Dots with that polka groove”,
“price”: 12.95
},
{
“id”: 2,
“title”: “Pebbles”,
“description”: “Just little rocks, really”,
“price”: 6.95
}
…etc…
]
we could write the query like so:
function ShoppingController($scope, $http) {
$http.get(‘/products’).success(function(data, status, headers, config) {
$scope.items = data;
});
}
and use it in a template like this:
<body ng-controller=”ShoppingController”>
<h1>Shop!</h1>
<table>
<tr ng-repeat=”item in items”>
<td>{{item.title}}</td>
<td>{{item.description}}</td>
<td>{{item.price | currency}}</td>
</tr>
</table>
</div>
</body>
It was just an overview and we can’t get into details in these type of articles. For details and reference, here are few links:
- AngularJS – Develop Smaller & Lighter Web Apps
- AngularJS by Google
- View on GitHub
- Download AngularJS 1.2.9
Suggested Pro Downloads
-

Hand Drawing Paper PSD Mockup
$2.99 Add to cart -
Sale!

Luxury 3D Gold Wall Logo Mockup PSD
Price range: $5.99 through $15.00 Select options This product has multiple variants. The options may be chosen on the product page -

Modern Spa & Massage Logo Design
$7.99 Add to cart -

Happy Businessman Jumping Vector Illustration
$1.49 Add to cart
Latest from @CreativeAlys YouTube Channel
70s Bubbly 3D Typography Tutorial | Adobe Illustrator
Flat 2D to 3D Stone Wall in Seconds! ⚡ #shorts #photoshop
How to Use 3D Stone Wall Logo Mockup in Photoshop (in 18 Seconds!) | CreativeAlys
Free 3D Stone Wall Logo Mockup PSD Tutorial | How to Edit & Customize in Photoshop
How to Display Latest YouTube Videos in WordPress (Free, Fast & No API Limits)
