AngularJS 1.x

      1. Interview questions and answers:

http://www.codeproject.com/Articles/891718/AngularJS-Interview-Questions-and-Answers

      1. Dependency Injection in Angular:

There are objects which can do injection (controller, directives, filters) and there are objects which can be injected(Factory, Service, Provider, Value, Constant). Injection process is as follows: 1) Injector gets an injection request, 2) Search service instances cache. 3) If it doesn’t find, lookup the relevant provider. 4) Call provier’s $get method. 5) Save results to service instances cache. 6) Inject the result (singleton) to the client.

https://www.tutorialspoint.com/angularjs/angularjs_dependency_injection.htm

      1. What is module? What is controller?

Module is a container. Controllers can be kept inside this container. It’s like a package. It has collection of component definitions.1

      1. What is a provider?

The provider() function allows us to create a configurable service where we can set input per application for the service created using the provider(). For example, if we need to set API kq89ey to access a service on the application level, we can set that in the module config and pass input to the provider using the $provide service. All the others ways to create services internally use the $provide service.

 

https://dzone.com/articles/what-is-a-provider-in-angularjs

      1. What is ng-repeat?

It is used for binding for data with more than one row.

      1. How to access webservices from angularJS?

Using $http.post(“service uri”).then(function(response){})

      1. What is $http service?

It is used to make HTTP request to remote server.$http({

Method: ‘GET’,

Url: ”

})

This returns a promise object, means it is an asynchronous call. Hence, we have to use then keyword. This has an error handling call section also.

 

      1. What is services in angular?

An object that provides a service just like any other service, which can be re-used in angular JS application. This is singleton in nature. Created by a provider’s $get method.

      1. Factory vs Service

Service is singleton in nature, where as Factory is not.

      1. Diff between Bind and Model in AngularJS

4NG-Bind is one way binding, where as ng-model is two way binding. Read-onl y fields should use bind, where as user editable fields can use model.

      1. How to pass promise through service:

http://stackoverflow.com/questions/16001400/how-can-i-pass-back-a-promise-from-a-service-in-angularjs

      1. Angular JS compilation of DOM elements and $compile and $link

When the DOM is done loading and the AngularJS process starts booting up, the first process that happens is the HTML is parsed by the browser as a DOM tree. This tree is then parsed using AngularJS’s $compile() method. $compile runs through the DOM tree and looks for directive declarations for the different DOM elements. Once all directive declarations are found for each DOM element and sorted (by priority, which we’ll get into shortly), the directive’s compile function is run and is expected to return a link() function. The $compile() function will return a linking function that wraps all of the containing DOM element’s directives’ linking functions.

Finally, the linking function is invoked with the containing scope that attaches all of the associated directives to that scope. This is where we’ll do most of the work when building directives, as this is where we can register listeners, set up watches, and add functionality. The result of this process is why the live data-binding exists between the scope and the DOM tree.

 

From <http://www.ng-newsletter.com/posts/directives.html>

 

      1. Config and Run in AngularJS:

 

      1. Configuring providers:

Configuring Providers

You may be wondering why anyone would bother to set up a full-fledged provider with the provide method if factory, value, etc. are so much easier. The answer is that providers allow a lot of configuration. We’ve already mentioned that when you create a service via the provider (or any of the shortcuts Angular gives you), you create a new provider that defines how that service is constructed. What I didn’t mention is that these providers can be injected into config sections of your application so you can interact with them!

First, Angular runs your application in two phases–the config and run phases. The configphase, as we’ve seen, is where you can set up any providers as necessary. This is also where directives, controllers, filters, and the like get set up. The run phase, as you might guess, is where Angular actually compiles your DOM and starts up your app.

You can add additional code to be run in these phases with the myMod.config and myMod.runfunctions–each take a function to run during that specific phase. As we saw in the first section, these functions are injectable–we injected the built-in $provide service in our very first code sample. However, what’s worth noting is that during the config phase, only providers can be injected (with the exception of the services in the AUTO module–$provide and $injector).

 

From <https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection#configuring-providers>

 

 

      1. Directives:

 

      1. Custom Directives:

http://www.ng-newsletter.com/posts/directives.html

      1. How to create Custom service in Angular?

App.factory(‘serviceName’,function(){ return {CallMe: function(input){return “”;}}})

      1. Routing in Angular
      2. ngRoute needs to be passed to module. And $routeprovider to function. Then use $routeProvider.when(“/home”,templateUrl: “”, controller:””})
      3. Enable HTML5 mode

$locationProvider.html5Mode(true);

AngularJS ng repeat directive

 

Leave a comment