1. Question:What are different ways to create service in AngularJS? 

    Answer
    There are five ways to create a service as given below:
    1. Service
    2. Factory
    3. Provider
    4. Value
    5. Constant






    1. Report
  2. Question:What is the difference between Factory, Service and Provider? 

    Answer
    Factory - A factory is a simple function which allows you to add some logic before creating the object. It returns the created object.
    
    When to use: It is just a collection of functions like a class. Hence, it can be instantiated in different controllers when you are using it with constructor function.
    
    Service - A service is a constructor function which creates the object using new keyword. You can add properties and functions to a service object by using this keyword. Unlike factory, it doesn’t return anything.
    
    When to use: It is a singleton object. Use it when you need to share a single object across the application.
    For example, authenticated user details.
    
    Provider - A provider is used to create a configurable service object. It returns value by using $get() function.
    
    When to use: When you need to provide module-wise configuration for your service object before making it available.






    1. Report
  3. Question:What is Routing in AngularJS? 

    Answer
    AngularJS Routing helps you to divide your app into multiple views and bind different views to Controllers. The magic of Routing is taken care by an AngularJS service $routeProvider. $routeProvider service provides method when() and otherwise() to define the routes for your app. Routing has dependency on ngRoute module.






    1. Report
  4. Question:Which components can be injected as a dependency in AngularJS? 

    Answer
    AngularJS provides a supreme Dependency Injection mechanism. It provides following core components which can be injected into each other as dependencies.
    
    value
    factory
    service
    provider
    constant






    1. Report
  5. Question:How to validate data in AngularJS? 

    Answer
    AngularJS enriches form filling and validation. We can use $dirty and $invalid flags to do the validations in seamless way. Use novalidate with a form declaration to disable any browser specific validation.
    
    Following can be used to track error.
    
    $dirty − states that value has been changed.
    
    $invalid − states that value entered is invalid.
    
    $error − states the exact error.






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd