1. Question:What is Controller in AngularJS? 

    Answer
    The controller defines the actual behavior of your app. It contains business logic for the view and connects the model to view with the help of $scope. A controller is associated with a HTML element with the ng-controller directive.

    1. Report
  2. Question:What is View in AngularJS? 

    Answer
    The view is responsible for presenting your models data to end user. Typically it is the HTML markup which exists after AngularJS has parsed and compiled the HTML to include rendered markup and bindings.

    1. Report
  3. Question:How to apply validation in AngularJS? 

    Answer
    AngularJS provides you built-in validation directives to validate form client side. This makes your life pretty easy to handle client-side form validations without adding a lot of extra effort. AngularJS form validations are based on the HTML5 form validators.
    
    AngularJS directives for form validation
    Here is a list of AngularJS directive which can be applied on an input field to validate its value.
    <input type="text"
       ng-model="{ string }"
       [name="{ string }"] 
       [ng-required="{ boolean }"] 
       [ng-minlength="{ number }"] 
       [ng-maxlength="{ number }"] 
       [ng-pattern="{ string }"] 
       [ng-change="{ string }"]> 
    </input>

    1. Report
  4. Question:What is Service in AngularJS? 

    Answer
    A service is a reusable singleton object which is used to organize and share code across your app. A service can be injected into controllers, filters, directives.
    
    AngularJS offers several built-in services (like $http, $provide, $resource, $window, $parse) which always start with $ sign.

    1. Report
  5. 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
  6. 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
  7. Question:What is the difference between $http and $resource? 

    Answer
    $http service is a core Angular service which allows you to make AJAX requests by using GET, HEAD, POST, PUT, DELETE, JSONP and PATCH methods. It is very much like the $.ajax() method in jQuery. It can be used with RESTful and Non-RESTful server-side data sources.
    
    $http is good for quick retrieval of server-side data that doesn’t really need any specific structure or complex behaviors.
    
    $resource warps $http and allows you to interact with RESTful server-side data sources. It requires the ngResource module to be installed which exist in angular-resource.js
    
    $http is good for retrieval of RESTful server-side data sources that might need any specific structure or complex behaviors.

    1. Report
  8. Question:What methods $http service support? 

    Answer
    The $http service supports the following methods:
    1. $http.get()
    2. $http.head()
    3. $http.post()
    4. $http.put()
    5. $http.delete()
    6. $http.jsonp()
    7. $http.patch()

    1. Report
  9. Question:How to enable caching in $http service? 

    Answer
    You can enable caching in $http service by setting configuration property cache to true. When cache is enabled, $http service stores the response from the server in local cache. In this way, next time the response will be served from the cache without sending request to server.
    $http.get("http://server/myserviceapi",{ cache:true }).sucess(function(){ 
    
    //TO DO: 
    
    });

    1. Report
  10. Question:What methods $resource service object support? 

    Answer
    The $resource service object supports the following methods:
    1. get()
    2. query()
    3. save()
    4. remove()
    5. delete()

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