Pitch your project

Random text






Blogs

0    
By admin Category Uncategorized, Posted February 12th, 2016
AngularJS Service

You can use a Angular service when you are writing code in the AngularJS framework. The Angular services is a function or a substitutable objects that stays connected in your application using the dependency injection (DI). Why use the Angular services? Because you organize your code so well and you can share code across your whole application. In AngularJS you have the choice to make your own services or use one of the many built-in services. AngularJS comes with about 30 built-in services. For example the $location and the $http service.By using a Angular service you add its as a dependency for your component.The angular dependency take care of the rest. In order to go in even deeper into the $http service, this service is one of the most used services in AngularJS applications. This is an AngularJS service for reading data from remote servers. The $http service will make a request tot he server and i twill return the response from the server. I will show you how to do this:

HTML

<div ng-app="myApp" ng-controller="myCtrl">
<p>Today's welcome message is:</p>

<h1>{{myWelcome}}</h1>

</div>

<p>The $http service requests a page on the server, and the response is set as the value of the "myWelcome" variable.</p>

AngularJS

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $http.get("welcome.htm")
  .then(function(response) {
      $scope.myWelcome = response.data;
  });
});
</script>

Result

Today’s welcome message is:

Hello AngularJS Students

The $http service requests a page on the server, and the response is set as the value of the “myWelcome” variable.

Posted by Nando Veenendaal

Comments

Leave a Reply

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