1. Question:How AngularJS handle the security? 

    Answer
    AngularJS provide following built-in protection from basic security holes:
    1. Prevent HTML injection attacks.
    2. Prevent Cross-Site-Scripting (CSS) attacks.
    3. Prevent XSRF protection for server side communication.
    
    Also, AngularJS is designed to be compatible with other security measures like Content Security Policy (CSP), HTTPS (SSL/TLS) and server-side authentication and authorization that greatly reduce the possible attacks.

    1. Report
  2. Question:What is difference between config() and run() method in AngularJS? 

    Answer
    Configuration block – This block is executed during the provider registration and configuration phase. Only providers and constants can be injected into configuration blocks. This block is used to inject module wise configuration settings to prevent accidental instantiation of services before they have been fully configured. This block is created using config() method.
    angular.module('myModule', []).config(function (injectables) {
      // provider-injector 
      // This is an example of config block. 
      // You can have as many of these as you want. 
      // You can only inject Providers (not instances) 
      // into config blocks. 
    }).run(function (injectables) { 
      // instance-injector 
      // This is an example of a run block. 
      // You can have as many of these as you want.
     // You can only inject instances (not Providers)
     // into run blocks 
    });
    Run block – This block is executed after the configuration block. It is used to inject instances and constants. This block is created using run() method. This method is like as main method in C or C++. The run block is a great place to put event handlers that need to be executed at the root level for the application. For example, authentication handlers.

    1. Report
  3. Question:Does AngularJS support MVC? 

    Answer
    AngularJS is a MVC framework. It does not implement MVC in the traditional way, but rather something closer to MVVM Model-View-ViewModel).

    1. Report
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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 © 2024. Powered by Intellect Software Ltd