Showing posts with label Angular JS. Show all posts
Showing posts with label Angular JS. Show all posts

Friday, August 19, 2016

Difference between ng-bind and expression

ng-bind not evaluate the html till the page is loading. If we use the expression {{expression}} then the html is evaluated and the values are flicked momentarily. Alternate to resolve this situation we can use ng-cloak. And put this css into css file.

[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  display: none !important;
} 

Thursday, August 11, 2016

Provider in Angular JS

All the web applications that we build uses Object that collaborate to get things done. These objects need to be instantiated.In angular, these objects are instantiated and wired by injector service.

Injector creates two types of objects - services and specialize objects.

Services objects are those API's that are defined by developer.
Specialized objects are defined specifically by Angular API, for e.g. controllers, directives, filters or animations.

Now, we have to specify that how to create these objects. There are five ways to create these objects.
* Value * Factory * Services * Constant and last but not the least Provider.

So, Lets discuss all one by one. I'll start by provider first.

Provider: Provider is the core of all type. All other are just the extension over it.
Provider is the implementation of $get method. This method is same like as we use in Factory.
Provider is used where we set the application-wide configuration that must be instantiated before the application start.

When angular application is going to bootstrap, before creating all the services, angular instantiates all providers.
Provider's are accessible during configuration phase, because services are not accessible at that time.
After completion of configuration phase, interaction with provider is not allowed and service instantiation process gets started.

Monday, August 8, 2016

Can we have more than one ng-app one page of Angular Js?

Yes, we can have more than one ng-app in one angular application. But the thing that we have to remember is, angular js bootstrap the first ng-app by default. if we want to bootstrap the another ng-app then we have to do it  explicitly by adding angular.bootstrap.

Note: You should not use the ng-app directive when manually bootstrapping your app. 


Eg: angular.bootstrap(document.getElementById("div1"),['myApp']);

Saturday, August 6, 2016

Events Propagation in Angular Js

In Angular JS events propagates in two ways, from parent to child or child to parent controller i.e. vise-versa.

To propagate event from parent to child we should use $broadcast.
To propagate event from child to parent we should use $emit.

Here is the plunker example.

https://plnkr.co/edit/?p=preview