AngularJS – Services

The service will helps to fetch data from the database when to share the data between controllers.
If we store the data inside a controller, once we change to another controller the data will be discarded.
AngularJS has 30 built in services.

Types of Services in AngularJS

  1. Built-in Services: The angularjs has inbuilt services. That’s is core services.
    The built in services like $http, $log, $location etc..
    The inbuilt services are always prefixed with $.
  2. Custom Services: These services are developed by developers to achieve certain business logic in the form of service.

The $http Service

The $http is the one of the inbult services in angularjs. It is commonly used services in angularjs application.

Example

Use the $http service to request data from the server:





Today's welcome message is:

{{myWelcome}}

From the above code we can clearly say that: The $http service requests a page on the server, and the response is set as the value of the “myWelcome” variable.

The $location Service

The $location service has methods which return information about the location of the current web page:

Example





The url of this page is:

{{myUrl}}

5 thoughts on “AngularJS – Services

  1. AlonzoRok

    На этом сайте можно найти онлайн игры на разные предпочтения.
    В разделах собраны разнообразные жанры: от шутеров до стратегий.
    Играйте соло или в многопользовательском режиме — всё доступно.
    Простой интерфейс и быстрый доступ игр точно оцените.
    Загляните и выберите подходящую игру уже сегодня!
    http://cowcreekranch.com/__media__/js/netsoltrademark.php?d=bundas24.com%2Fread-blog%2F188807

  2. Bennyscatt

    На данном сайте можно найти информацией о решениях видеонаблюдения, разновидностях и ключевых характеристиках. Здесь представлены полезные сведения о выборе оборудования, монтаже и конфигурации.
    видеонаблюдение

  3. eco Product

    Hey there! Do you know if they make any plugins to assist with
    Search Engine Optimization? I’m trying to get my website to
    rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Thank you!

    You can read similar blog here: Wool product

Leave a Reply

Your email address will not be published.