Category: Angular

  • What is NGRX and Use of NGRX

    What is NGRX and Use of NGRX

    So, In the previous blog, we learn what is State management and the benefit of State in our App. I gave you a basic idea about the store in the previous blog. But in this blog post, I will give you more detail about the store of NGRS.

    Store, As the name we can assume that it is related to storing data. Yes, Store is an in-memory DB on the client-side. It is the main part of State management because whatever you want to keep state you need some kind of storage, State helps you in that. The state is immutable which means you can not change it directly. It can only be changed with the reducers by keeping it immutable.

    So, In short, we can say the state is only in-memory storage.

    Now, let’s move to its friends which are Action, Reducers, And Dispatcher.

    Action: AS we can assume with its name it defines which kind of Action we want to perform. Yes, the action is used to define the type of action/event such as ADD, UPDATE, DELETE, GET. But again we can not act directly on Store. So we need to take help from Reducers.

    Reducers: As we know the Store cannot be modified directly so the reducer handles the transition from one state to another state of Store.

    Dispatcher: Dispatcher is required to pass the action to Store.

    Here is the simple lifecycle which helps you to understand the flow of NGRX

    In the next blog, I will create a small app using NGRX so, till that stay tuned. Happy Coding…

  • What is State Management in Angular? How to improve Performance?

    Is your application is really big or made for enterprise-level? Is your application consuming the same APIs again and again to fetch the same data on each action?

    Then you are doing the wrong implementation, my dear friend.

    You should maintain the State of Application just like you heard in React.js using Redux.

    Yes, you can manage the state in Angular2+ application using NGRX.

    Now before heading forward to NGRX many of you don’t know about the state and why the state management is required.

    So, What is State Management?

    I can bet your current application also maintaining the state. But that is not the proper state management.

    Let me, explain to you about State Management. “State” term includes both the state of UI and the state of variables in your code. So any change in your application changes the state.

    Now each component has its state and a component has no idea about the other components’ states unless we make enable the data flow between components using service or Input/Output decorators which means whenever you left the Module or component that means the state of that component/module destroyed. So, When you again load that component then you need to recall the API or need to assign value to a variable so your application can render the data.

    Now let me give the nightmare situation about your application.

    Suppose you have an application that has a module called Customer List. and that list contains 140 Customers. Now imaging when the user comes to that module the first API trigger to fetch 50 Customers. Now you edit a customer. So, again you called an API to fetch the customer information. you saved the customer and come back to the customers’ list. so, again you call the API because you need updated data. right?

    So, in this basic workflow, your application called 3 GET APIs and 1 PUT API.

    Now think your application has hundreds of users. and have millions of records. So, can you imagine how many API transactions will happen and how much load server has to take? And also the application user has to wait until the API transaction gets completed each time.

    Now a very common question comes in mind is, How can I overcome this issue?

    The answer is very simple to store the data in Entity/Variable.

    Here our Hero comes in the picture which is ngrx/store.

    The store is some kind of database for the client-side. Store save the data as the “Single Source of Truth”.

    What exactly the Store do to resolve our problem?

    The store can not do anything on its own it also needs helping hands. And the helping hands are Action, Reducers, and Dispatcher.

    Now the truth is the thing which can not be modified after storing data that is why Store is the single source of truth. which means the Store is read-only or immutable.

    So, now you know better about the store and state management and why it should be required in all the Angular Application.

    In the next article, I will give brief information about Action, Reducers, and Dispatcher.

    I will also give you a few architectures about the application from simple to complex applications. And also a simple demo as well. Till that stay tuned.

    Don’t forget to subscribe to the notification of my blog so you will get quick notification whenever I post new articles.

  • Angular Typescript Geo Info Module

    An (AOT ready) Angular (4+) service for Geo coordination.

    Installation

    npm install ngx-geo-info-angular --save
    

     
    Add the cookie service to your app.module.ts as a provider:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';
    import { AppComponent } from './app.component';
    import { NgxGeoCoordinatesInfoModule } from 'ngx-geo-info-angular';
    @NgModule({
      declarations: [ AppComponent ],
      imports: [ BrowserModule, FormsModule, HttpModule, NgxGeoCoordinatesInfoModule ],
      bootstrap: [ AppComponent ]
    })
    export class AppModule { }

    Then, import and inject it into a component:

    import { Component, OnInit } from '@angular/core';
    import { NgxGeoCoordinatesInfo } from 'ngx-geo-info-angular';
    @Component({
      selector: 'demo-root',
      templateUrl: './app.component.html',
      styleUrls: [ './app.component.scss' ]
    })
    export class AppComponent implements OnInit {
      constructor( private geoService: NgxGeoCoordinatesInfo ) { }
      ngOnInit(): void {
        this.geoService.getAll().then(value => {
          console.log(value);
        }, (err) => {
            console.log(value);
        });
        this.geoService.get('latitude').then(value => {
          console.log(value);
        }, (err) => {
            console.log(value);
        });
        this.geoService.get('longitude').then(value => {
          console.log(value);
        , (err) => {
            console.log(value);
        });
      }
    }
    

    That’s it!


    Methods

    get( name: string ): string;

    this.geoService.get('latitude').then(value => {
          console.log(value);
    }, (err) => {
          console.log(value);
    });

    getAll(): {};

    this.geoService.getAll().then(value => {
          console.log(value);
    }, (err) => {
          console.log(value);
    });
    

    Parameter

    {
      accuracy : <number>,
      altitude : <it work if your browser support>,
      altitudeAccuracy : <it work if your browser support>,
      heading : <it work if your browser support>,
      latitude : <double/float>,
      longitude : <double/float>,
      speed : <it work if your browser support>,
      timestamp : <number (TimeStamp) when you get the information>,
    }

    Error Response

    {
        status : error,
        message: 'Error Message',
        data:{
            accuracy : '',
            altitude : '',
            altitudeAccuracy : '',
            heading : '',
            latitude :'',
            longitude : '',
            speed : '',
            timestamp : '',
        }
    }

    Success Response

    {
        status : 'success',
        message: '',
        data: {
            accuracy : <number>,
            altitude : <it work if your browser support>,
            altitudeAccuracy : <it work if your browser support>,
            heading : <it work if your browser support>,
            latitude : <double/float>,
            longitude : <double/float>,
            speed : <it work if your browser support>,
            timestamp : <number (TimeStamp) when you get the information>,
        }
    }

    NPM URL: https://www.npmjs.com/package/ngx-geo-info-angular

  • Angular 6: Remove Object from Array of Object on Conditional Based

    Angular 6: Remove Object from Array of Object on Conditional Based

    Its very hard to remove specific conditional based object removal from Array of Objects.

    So, Here is my solutions.

    To do this we need to make the recursive function which calls and traverse all the child and find the specific data which match with our condition.

    In this example, I want to remove data which has blank BusinessID.

    So first I create a wrapper function or we can call it parent function.

    FilterData(Data: any[]) {
        let tempReturn: any;
        let childReturn: any;
        Data.forEach(data =&amp;amp;gt; {
          childReturn = []
          if (data['ChildAccounts'].length &amp;amp;gt; 0) {
            childReturn = this.hyrarchyData(data['ChildAccounts']);
          }
          if (data['BusinessID'] === '') {
            tempReturn = { 'AccountID': data.AccountID, 'AccountName': data.AccountName, 'BusinessID': data.BusinessID, 'ChildAccounts': childReturn };
          } else {
            tempReturn = this.simplyfyArrayToObject(childReturn);
          }
          if (tempReturn !== undefined &amp;amp;amp;&amp;amp;amp; tempReturn !== null) {
            this.FilteredData.push(tempReturn);
          }
        })
      }

    As we can see in this function first we are checking if the Array of Objects has child or not. If we have the child then we need to traverse the child first and then we add that child to parent object.

    For the child, I explain later. but first, let’s understand the parent functionality.

    After calling child function we check our condition. If it matches with our requirement then we create another object assign value to that object then push to our global variable.

    Now you can see that I have created another function called “simplyfyArrayToObject”. This function just check if we have Array of Array (Nested) which we don’t want but still it creates because We have It’scondition which might not match with Parent object but match with child so in that case, it create Array of Array.

    And at last we just check that if the variable exists then we simply push to Global variable.

    Now come to the process of child node.

    [code lang=”js”]hyrarchyData(Data: any[]) {
    let tempReturn: any;
    let childReturn: any;
    let returnObj = [];
    Data.forEach(data =&amp;amp;gt; {
    childReturn = [];
    if (data['ChildAccounts'].length &amp;amp;gt; 0) {
    childReturn = this.hyrarchyData(data['ChildAccounts']);
    }
    if (data['BusinessID'] === '') {
    tempReturn = { 'AccountID': data.AccountID, 'AccountName': data.AccountName, 'BusinessID': data.BusinessID, 'ChildAccounts': childReturn };
    } else {
    tempReturn = this.simplyfyArrayToObject(childReturn);
    }
    returnObj.push(tempReturn);
    });
    return returnObj;
    }[/code]

    This function is recursive and does the same which our parent function is doing. Only the differnce is that our parent function push the value to global but this push to local varibale and return that varibal.

  • Build Ultra-Modern Web Apps with Angular Material

    Build Ultra-Modern Web Apps with Angular Material

    At the Google I/O Conference back in 2014, Google announced Material Design, their new design language. They have since converted much of their popular applications to adhere to this new spec in an effort to provide a consistent experience. Now they are trying to convince you to follow along as well.
    Angular Material: Superheroic Javascript Framework Meets Ultra-Modern Design

    What is Material Design?

    After a visit to the official Material Design spec, you will immediately get a feeling of ultra-modern minimalism. Basic shapes and flat colors are the theme here. Going through the documentation is quite an experience. I recommend taking a look for yourself, but I will summarize it here.

    Goal

    The purpose is to create a visual language that synthesizes classic principles of good design with the innovation and possibility of technology and science. Also to develop a single underlying system that allows for a unified experience across various platforms and device sizes.

    Principles

    Material Design is founded on three principles.

    Material Is the Metaphor

    Inspired by the study of paper and ink, the material lives in 3D space and is grounded in tactile reality. It gives the illusion of space by using realistic shadows. The paper material must abide by the laws of physics (i.e. two pieces of paper may not travel through each other), but may supercede the physical world (i.e. a paper may grow or shrink).

    Bold, Graphic, Intentional

    Deliberate color choices, edge-to-edge imagery, large-scale typography, and intentional white space create a bold and graphic interface that immerse the user in the experience. The Floating Action Button, or FAB, is a prime example of this principle. Have you noticed that little circle with the ‘plus’ symbol floating around in your Google Inbox app? Material Design makes it very apparent that this is an important button.

    Motion Provides Meaning

    Motion is meaningful and appropriate, serving to focus attention and maintain continuity. Feedback is subtle yet clear. Transitions are efficient yet coherent. The main point here is to animate only when it has a purpose and not to overdo it.

    How does AngularJS fit into Material Design?

    AngularJS, Google’s “Superheroic JavaScript MVW Framework”, addresses many of the challenges encountered in developing single-page applications (SPA). It provides the framework needed for creating modern web applications that connect to APIs and never need the page to be refreshed.

    AngularJS: A New Approach

    Angular is what HTML would have been, had it been designed for applications. HTML is a great declarative language for static documents, but creating dynamic applications not so much.
    Creating dynamic applications with HTML has always been an exercise in tricking the browser into doing things it wasn’t meant to do. There are a couple of approaches to doing this.

    1. Library – a collection of functions. (jQuery)
    2. Framework – code dynamically fills in static elements when needed. (Durandal, Ember)

    Angular takes a different approach to solve this problem. Instead of struggling with the HTML it is given, it creates new HTML constructs. Angular teaches the browser new HTML syntax through a construct called ‘directives’. Angular comes with a set of these directives built-in, but also allows you to create custom directives, so it allows you to write your own HTML elements.
    Wouldn’t it be neat if Google created a set of directives based on Material Design principles?

    Introducing Angular Material

    Google is actively developing Angular Material, an implementation of Material Design in AngularJS. Angular Material provides a set of reusable UI components based on the Material Design system. Angular Material is composed of several pieces. It has a CSS library for typography and other elements, it provides an interesting JavaScript approach for theming, and its responsive layout uses a flex grid. But the most appealing feature of Angular Material is its amazing collection of directives.

    Getting Started

    I have created an open source project to help jumpstart your next Angular Material project. The purpose of this project is to give an example of everything Angular Material has to offer, all under one roof. Navigation, paging, theming, and the entire collection of directives are ready to go, all you have to do is feed in your data and bind it to the HTML.
    Take a look at the demo here or fork the code on GitHub.

    Directives

    Directives are a core Angular feature. Angular comes with several directives that you use all of the time like ng-model or ng-repeat. They are a very important piece of Angular that makes the framework function as it should.

    How to Use an Angular Material Directive

    Angular Material extends this directive library with a set of beautiful Material Design inspired directives. Angular Material directives are HTML tags that begin with ‘md’; short for Material Design. They couldn’t be much easier to use. For example, let’s take a look at the good old button.
    A standard HTML button might look something like this.

    <button>Click Me</button>
    

    An Angular Material button looks like this.

    <md-button>Click Me</md-button>
    

    And this is all that is needed to make a Material button. Now, there are several other options that are available for this directive such as theming it and raising it from the surface to imply importance.

    <md-button class="md-raised md-primary md-hue-1">Click Me</md-button>
    

    Services

    Services are also core to Angular functionality. They are used to share code across the application. A common core service like $http is used and reused for data calls in Angular applications.
    Angular services are:

    1. Lazily instantiated – Angular only instantiates a service when an application component depends on it.
    2. Singletons – Each component dependent on a service gets a reference to the single instance generated by the service factory.

    How to Use an Angular Material Service

    Angular Material comes packaged with some services that provide some extra functionality to the application. They also contribute to the performance of some of the directives. A great example of a service is the ‘toast’.

    A toast is a small notification that slides in from the top of the screen and goes away after a few seconds. Using this service is easy.
    In JavaScript,

    $mdToast.show(
          $mdToast.simple('Simple Toast!')
            .position('left bottom')
            .hideDelay(3000)
        );
    

    This example shows a simple toast that pops up on the bottom left of the screen and retreats after 3 seconds.
    Some services can be personalized with custom templates. In this case, the $mdToast service can use a custom HTML template by using the md-toast directive.

    Theming

    Material Design is a visual language where themes convey meaning through color, tones, and contrast. These themes are expressed throughout the components in the entire application to provide a more unified feel.

    According to the Material Design guidelines, you must “limit your selection of colors by choosing three color hues from the primary palette and one accent color from the secondary palette.” Angular Material makes following this guideline simple by using JavaScript to configure the theme. But first, what is a palette and a hue?

    • Hue: A hue is a single color in a palette.
    • Palette: A palette is a collection of hues.

    For example, a palette would be ‘green’ and a hue is a particular shade of green. Angular Material comes packaged with all of the valid palettes from the Material Design spec. You can learn about more about the valid color palettes here.

    Configuring the Theme

    Theming your project is a piece of cake. In the app.js file, set your desired palettes and hues using the Theming Provider service.

    angular.module('myApp', ['ngMaterial'])
    .config(function($mdThemingProvider) {
      $mdThemingProvider.theme('default')
        .primaryPalette(‘cyan’, {
          'default': '400',
          'hue-1': '100',
          'hue-2': '600',
          'hue-3': 'A100'
        })
        .accentPalette('amber')
        .warnPalette('red')
        .backgroundPalette('grey');
    });
    

    Using the Theme

    To apply the theme to the components, set the class of the element to the desired palette and hue.

    <md-button class="md-primary">Click me</md-button>
    <md-button class="md-primary md-hue-1">Click me</md-button>
    <md-button class="md-primary md-hue-2">Click me</md-button>
    <md-button class="md-accent">or maybe me</md-button>
    <md-button class="md-warn">Careful</md-button>
    

    Layout

    Flexbox is the latest and greatest addition to responsive design and Angular Material comes packaged with it. If you are familiar with the Bootstrap grid system, then you should be able to catch on quickly. In fact, Bootstrap is switching to Flexbox in its upcoming release. It has the familiar rows and columns layout you have become accustomed to, but with much more. Learn how to use Flexbox with this tutorial or study theofficial documentation.

    Top 9 Best Angular Material Directives

    There are too many Angular Material directives to list them all, so I would like to share with you my favorites.

    9. Progress Linear

    Often in SPAs, pages need time to load data from the server. If the application shows a blank page during this time, users may think the application is broken and will leave. Let users know the data is loading with theProgress Linear directive. Users will know to wait when they see an animated progress bar indicating that something is happening. Alternatively, use the Progress Circular directive for a round indicator.

    8. Date Picker

    The Date Picker directive makes choosing a date a clean, simple experience for the user and a true one-liner to write. Simply use md-datepicker and optionally confine the range with md-min-date and md-max-date and that’s it.

    7. Autocomplete

    Autocomplete provides a pleasant user experience by helping the user choose an option. It is what makes Google’s search engine the best. The Autocomplete directive adds this functionality to your application by completing a user’s words as they type. But the best part about this directive is customization. By filling your autocomplete with md-item-template you can give more meaning to the suggestions. For instance, if a user was searching for names in a company, the autocomplete could show the matching names with their picture and company role, giving a more robust user experience.

    6. Bottom Sheet

    The bottom sheet is a little menu that slides up from the bottom of your screen, covering content and taking focus. Originally intended to be used solely for mobile devices, the bottom sheet has been gaining popularity on larger screens. To use it, create a template with md-bottom-sheet containing either an md-grid or an md-list for a grid layout or list layout, respectively. Then call it with the Bottom Sheet service, $mdBottomSheet.show().

    5. Input

    Input forms are boring and have been since the beginning of the internet. But they don’t have to be! Give yourinputs some flair with the Input directive. Wrap your input tag with md-input-container and watch it come to life. Watch as your placeholder animates into a floating label. Easily validate your input with instant, but subtle, color changes and warning messages. Input directive takes an element that is expected to be boring and delivers a pleasant surprise.

    4. Toast

    The most aggravating user experience is not knowing what the application is doing. We ease this aggravation with toasters, or little unobtrusive notifications. In the olden days, when we sent a request to the server we waited on that page until the response came back before we could move on. User attention span has dropped drastically since then. In today’s SPAs, we click a button and expect to move along immediately, dealing with the server response when it comes. The Toast directive makes this a piece of cake. A toaster is summoned by simply using the Toast Service, $mdToast.show(), and setting the text, duration, and which corner to appear in. Make your own custom toaster with md-toast.

    3. Grid List

    Are your lists lacking pizazz? Grid lists are an alternative to standard list views. A grid list is best for presenting images, and is optimized for visual comprehension. It works by laying different sized tiles on a grid, giving a scattered, eclectic feel. The tile size and layout then respond to the screen size. This directive is sure to give your application an exciting and fun look.

    2. Whiteframe

    The concept of space is the core of Material Design and its paper metaphor. Two sheets of paper in the same z-position (or depth), form a seam and must move together. Two overlapping sheets of paper, with different z-positions, form a step. They move independently of each other. To follow the design, we must be able to shift elements along the z-axis. Angular Material provides a simple way to do this. Using the Whiteframe directive, set the class to md-whiteframe-z{x}, where x is the units of depth up from the background. The larger the number, the larger the shadow cast by the paper.

    1. Sidenav

    Creating a side navigation menu has never been easier. The Sidenav directive places a navigation menu on either the left or right of the screen. Keeping mobile in mind, it swipes in and out as expected, or programmatically with a button click. A nice addition is the lock open feature. The side navigation can be set to lock open when the screen reaches a certain size. By setting the parameter md-is-locked-open=”$mdMedia(‘gt-sm’)” the menu will be tucked away on the phone but locked open on tablet and larger.

    Conclusion

    Google is converting their most popular applications to Material Design. Now they are heading the development of Angular Material, an implementation of Material Design written in AngularJS. Material Design uses a paper metaphor, bold intentions, and meaningful motion. AngularJS organizes single page applications. Angular Material applies Material Design principles to AngularJS applications.
    Material Design is here and Angular Material is a fantastic way to apply the Material design spec to your single page applications. If you want to create your own Angular Material application, don’t waste your time starting from scratch. Rather, start off with a fully functioning app with demos of the directives, theming already set up, and navigation and routing ready to go. Take a look at the demo here or fork the code on GitHub. Of course, you can also learn all about Angular Material by visiting the official documentation.
    What do you think about my picks for the best Angular Material directives? Did I get them right? What are your favorites?
    Source: Toptal

  • Build Ultra-Modern Web Apps with Angular Material

    At the Google I/O Conference back in 2014, Google announced Material Design, their new design language. They have since converted much of their popular applications to adhere to this new spec in an effort to provide a consistent experience. Now they are trying to convince you to follow along as well.
    Angular Material: Superheroic Javascript Framework Meets Ultra-Modern Design

    What is Material Design?

    After a visit to the official Material Design spec, you will immediately get a feeling of ultra-modern minimalism. Basic shapes and flat colors are the theme here. Going through the documentation is quite an experience. I recommend taking a look for yourself, but I will summarize it here.

    Goal

    The purpose is to create a visual language that synthesizes classic principles of good design with the innovation and possibility of technology and science. Also to develop a single underlying system that allows for a unified experience across various platforms and device sizes.

    Principles

    Material Design is founded on three principles.

    Material Is the Metaphor

    Inspired by the study of paper and ink, the material lives in 3D space and is grounded in tactile reality. It gives the illusion of space by using realistic shadows. The paper material must abide by the laws of physics (i.e. two pieces of paper may not travel through each other), but may supercede the physical world (i.e. a paper may grow or shrink).

    Bold, Graphic, Intentional

    Deliberate color choices, edge-to-edge imagery, large-scale typography, and intentional white space create a bold and graphic interface that immerse the user in the experience. The Floating Action Button, or FAB, is a prime example of this principle. Have you noticed that little circle with the ‘plus’ symbol floating around in your Google Inbox app? Material Design makes it very apparent that this is an important button.

    Motion Provides Meaning

    Motion is meaningful and appropriate, serving to focus attention and maintain continuity. Feedback is subtle yet clear. Transitions are efficient yet coherent. The main point here is to animate only when it has a purpose and not to overdo it.

    How does AngularJS fit into Material Design?

    AngularJS, Google’s “Superheroic JavaScript MVW Framework”, addresses many of the challenges encountered in developing single-page applications (SPA). It provides the framework needed for creating modern web applications that connect to APIs and never need the page to be refreshed.

    AngularJS: A New Approach

    Angular is what HTML would have been, had it been designed for applications. HTML is a great declarative language for static documents, but creating dynamic applications not so much.
    Creating dynamic applications with HTML has always been an exercise in tricking the browser into doing things it wasn’t meant to do. There are a couple of approaches to doing this.

    1. Library – a collection of functions. (jQuery)
    2. Framework – code dynamically fills in static elements when needed. (Durandal, Ember)

    Angular takes a different approach to solve this problem. Instead of struggling with the HTML it is given, it creates new HTML constructs. Angular teaches the browser new HTML syntax through a construct called ‘directives’. Angular comes with a set of these directives built-in, but also allows you to create custom directives, so it allows you to write your own HTML elements.
    Wouldn’t it be neat if Google created a set of directives based on Material Design principles?

    Introducing Angular Material

    Google is actively developing Angular Material, an implementation of Material Design in AngularJS. Angular Material provides a set of reusable UI components based on the Material Design system. Angular Material is composed of several pieces. It has a CSS library for typography and other elements, it provides an interesting JavaScript approach for theming, and its responsive layout uses a flex grid. But the most appealing feature of Angular Material is its amazing collection of directives.

    Getting Started

    I have created an open source project to help jumpstart your next Angular Material project. The purpose of this project is to give an example of everything Angular Material has to offer, all under one roof. Navigation, paging, theming, and the entire collection of directives are ready to go, all you have to do is feed in your data and bind it to the HTML.
    Take a look at the demo here or fork the code on GitHub.

    Directives

    Directives are a core Angular feature. Angular comes with several directives that you use all of the time like ng-model or ng-repeat. They are a very important piece of Angular that makes the framework function as it should.

    How to Use an Angular Material Directive

    Angular Material extends this directive library with a set of beautiful Material Design inspired directives. Angular Material directives are HTML tags that begin with ‘md’; short for Material Design. They couldn’t be much easier to use. For example, let’s take a look at the good old button.
    A standard HTML button might look something like this.

    <button>Click Me</button>
    

    An Angular Material button looks like this.

    <md-button>Click Me</md-button>
    

    And this is all that is needed to make a Material button. Now, there are several other options that are available for this directive such as theming it and raising it from the surface to imply importance.

    <md-button class="md-raised md-primary md-hue-1">Click Me</md-button>
    

    Services

    Services are also core to Angular functionality. They are used to share code across the application. A common core service like $http is used and reused for data calls in Angular applications.
    Angular services are:

    1. Lazily instantiated – Angular only instantiates a service when an application component depends on it.
    2. Singletons – Each component dependent on a service gets a reference to the single instance generated by the service factory.

    How to Use an Angular Material Service

    Angular Material comes packaged with some services that provide some extra functionality to the application. They also contribute to the performance of some of the directives. A great example of a service is the ‘toast’.

    A toast is a small notification that slides in from the top of the screen and goes away after a few seconds. Using this service is easy.
    In JavaScript,

    $mdToast.show(
          $mdToast.simple('Simple Toast!')
            .position('left bottom')
            .hideDelay(3000)
        );
    

    This example shows a simple toast that pops up on the bottom left of the screen and retreats after 3 seconds.
    Some services can be personalized with custom templates. In this case, the $mdToast service can use a custom HTML template by using the md-toast directive.

    Theming

    Material Design is a visual language where themes convey meaning through color, tones, and contrast. These themes are expressed throughout the components in the entire application to provide a more unified feel.

    According to the Material Design guidelines, you must “limit your selection of colors by choosing three color hues from the primary palette and one accent color from the secondary palette.” Angular Material makes following this guideline simple by using JavaScript to configure the theme. But first, what is a palette and a hue?

    • Hue: A hue is a single color in a palette.
    • Palette: A palette is a collection of hues.

    For example, a palette would be ‘green’ and a hue is a particular shade of green. Angular Material comes packaged with all of the valid palettes from the Material Design spec. You can learn about more about the valid color palettes here.

    Configuring the Theme

    Theming your project is a piece of cake. In the app.js file, set your desired palettes and hues using the Theming Provider service.

    angular.module('myApp', ['ngMaterial'])
    .config(function($mdThemingProvider) {
      $mdThemingProvider.theme('default')
        .primaryPalette(‘cyan’, {
          'default': '400',
          'hue-1': '100',
          'hue-2': '600',
          'hue-3': 'A100'
        })
        .accentPalette('amber')
        .warnPalette('red')
        .backgroundPalette('grey');
    });
    

    Using the Theme

    To apply the theme to the components, set the class of the element to the desired palette and hue.

    <md-button class="md-primary">Click me</md-button>
    <md-button class="md-primary md-hue-1">Click me</md-button>
    <md-button class="md-primary md-hue-2">Click me</md-button>
    <md-button class="md-accent">or maybe me</md-button>
    <md-button class="md-warn">Careful</md-button>
    

    Layout

    Flexbox is the latest and greatest addition to responsive design and Angular Material comes packaged with it. If you are familiar with the Bootstrap grid system, then you should be able to catch on quickly. In fact, Bootstrap is switching to Flexbox in its upcoming release. It has the familiar rows and columns layout you have become accustomed to, but with much more. Learn how to use Flexbox with this tutorial or study the official documentation.

    Top 9 Best Angular Material Directives

    There are too many Angular Material directives to list them all, so I would like to share with you my favorites.

    9. Progress Linear

    Often in SPAs, pages need time to load data from the server. If the application shows a blank page during this time, users may think the application is broken and will leave. Let users know the data is loading with the Progress Linear directive. Users will know to wait when they see an animated progress bar indicating that something is happening. Alternatively, use the Progress Circular directive for a round indicator.

    8. Date Picker

    The Date Picker directive makes choosing a date a clean, simple experience for the user and a true one-liner to write. Simply use md-datepicker and optionally confine the range with md-min-date and md-max-date and that’s it.

    7. Autocomplete

    Autocomplete provides a pleasant user experience by helping the user choose an option. It is what makes Google’s search engine the best. The Autocomplete directive adds this functionality to your application by completing a user’s words as they type. But the best part about this directive is customization. By filling your autocomplete with md-item-template you can give more meaning to the suggestions. For instance, if a user was searching for names in a company, the autocomplete could show the matching names with their picture and company role, giving a more robust user experience.

    6. Bottom Sheet

    The bottom sheet is a little menu that slides up from the bottom of your screen, covering content and taking focus. Originally intended to be used solely for mobile devices, the bottom sheet has been gaining popularity on larger screens. To use it, create a template with md-bottom-sheet containing either an md-grid or an md-list for a grid layout or list layout, respectively. Then call it with the Bottom Sheet service, $mdBottomSheet.show().

    5. Input

    Input forms are boring and have been since the beginning of the internet. But they don’t have to be! Give your inputs some flair with the Input directive. Wrap your input tag with md-input-container and watch it come to life. Watch as your placeholder animates into a floating label. Easily validate your input with instant, but subtle, color changes and warning messages. Input directive takes an element that is expected to be boring and delivers a pleasant surprise.

    4. Toast

    The most aggravating user experience is not knowing what the application is doing. We ease this aggravation with toasters, or little unobtrusive notifications. In the olden days, when we sent a request to the server we waited on that page until the response came back before we could move on. User attention span has dropped drastically since then. In today’s SPAs, we click a button and expect to move along immediately, dealing with the server response when it comes. The Toast directive makes this a piece of cake. A toaster is summoned by simply using the Toast Service, $mdToast.show(), and setting the text, duration, and which corner to appear in. Make your own custom toaster with md-toast.

    3. Grid List

    Are your lists lacking pizazz? Grid lists are an alternative to standard list views. A grid list is best for presenting images, and is optimized for visual comprehension. It works by laying different sized tiles on a grid, giving a scattered, eclectic feel. The tile size and layout then respond to the screen size. This directive is sure to give your application an exciting and fun look.

    2. Whiteframe

    The concept of space is the core of Material Design and its paper metaphor. Two sheets of paper in the same z-position (or depth), form a seam and must move together. Two overlapping sheets of paper, with different z-positions, form a step. They move independently of each other. To follow the design, we must be able to shift elements along the z-axis. Angular Material provides a simple way to do this. Using the Whiteframe directive, set the class to md-whiteframe-z{x}, where x is the units of depth up from the background. The larger the number, the larger the shadow cast by the paper.

    1. Sidenav

    Creating a side navigation menu has never been easier. The Sidenav directive places a navigation menu on either the left or right of the screen. Keeping mobile in mind, it swipes in and out as expected, or programmatically with a button click. A nice addition is the lock open feature. The side navigation can be set to lock open when the screen reaches a certain size. By setting the parameter md-is-locked-open=”$mdMedia(‘gt-sm’)” the menu will be tucked away on the phone but locked open on tablet and larger.

    Conclusion

    Google is converting their most popular applications to Material Design. Now they are heading the development of Angular Material, an implementation of Material Design written in AngularJS. Material Design uses a paper metaphor, bold intentions, and meaningful motion. AngularJS organizes single page applications. Angular Material applies Material Design principles to AngularJS applications.
    Material Design is here and Angular Material is a fantastic way to apply the Material design spec to your single page applications. If you want to create your own Angular Material application, don’t waste your time starting from scratch. Rather, start off with a fully functioning app with demos of the directives, theming already set up, and navigation and routing ready to go. Take a look at the demo here or fork the code on GitHub. Of course, you can also learn all about Angular Material by visiting the official documentation.
    What do you think about my picks for the best Angular Material directives? Did I get them right? What are your favorites?

  • A Step-by-Step Tutorial for Your First AngularJS App

    What is AngularJS?

    AngularJS is a JavaScript MVC framework developed by Google that lets you build well structured, easily testable, and maintainable front-end applications.

    And Why Should I Use It?

    If you haven’t tried AngularJS yet, you’re missing out. The framework consists of a tightly integrated toolset that will help you build well structured, rich client-side applications in a modular fashion—with less code and more flexibility.
    AngularJS extends HTML by providing directives that add functionality to your markup and allow you to create powerful dynamic templates. You can also create your own directives, crafting reusable components that fill your needs and abstracting away all the DOM manipulation logic.
    It also implements two-way data binding, connecting your HTML (views) to your JavaScript objects (models) seamlessly. In simple terms, this means that any update on your model will be immediately reflected in your view without the need for any DOM manipulation or event handling (e.g., with jQuery).

    Angular provides services on top of XHR that dramatically simplify your code and allow you to abstract API calls into reusable services. With that, you can move your model and business logic to the front-end and build back-end agnostic web apps.

    Finally, I love Angular because of its flexibility regarding server communication. Like most JavaScript MVC frameworks, it lets you work with any server-side technology as long as it can serve your app through a RESTful web API. But Angular also provides services on top of XHR that dramatically simplify your code and allow you to abstract API calls into reusable services. As a result, you can move your model and business logic to the front-end and build back-end agnostic web apps. In this post, we’ll do just that, one step at a time.

    So, Where Do I Begin?

    First, let’s decide the nature of the app we want to build. In this guide, we’d prefer not to spend too much time on the back-end, so we’ll write something based on data that’s easily attainable on the Internet—like a sports feed app!
    Since I happen to be a huge fan of motor racing and Formula 1, I’ll use an autosport API service to act as our back-end. Luckily, the guys at Ergast are kind enough to provide a free motorsport API that will be perfect for us.
    For a sneak peak at what we’re going to build, take a look at the live demo. To prettify the demo and show off some Angular templating, I applied a Bootstrap theme from WrapBootstrap, but seeing as this article isn’t about CSS, I’ll just abstract it away from the examples and leave it out.

    Getting Started Tutorial

    Let’s kickstart our example app with some boilerplate. I recommend the angular-seed project as it not only provides you with a great skeleton for bootstrapping, but also sets the ground for unit testing with Karma and Jasmine (we won’t be doing any testing in this demo, so we’ll just leave that stuff aside for now; see Part 2 of this tutorial for more info on setting up your project for unit and end-to-end testing).
    EDIT (May 2014): Since I wrote this tutorial, the angular-seed project has gone through some heavy changes (including the additon of Bower as package manager). If you have any doubts about how to deploy the project, take a quick look at the first section of their reference guide. In Part 2 of ths tutorial, Bower, among other tools, is covered in greater detail.
    OK, now that we’ve cloned the repository and installed the dependencies, our app’s skeleton will look like this:

    angularjs tutorial - start with the skeleton

    Now we can start coding. As we’re trying to build a sports feed for a racing championship, let’s begin with the most relevant view: the championship table.

    the championship table

    Given that we already have a drivers list defined within our scope (hang with me – we’ll get there), and ignoring any CSS (for readability), our HTML might look like:

    <body ng-app="F1FeederApp" ng-controller="driversController">
      <table>
        <thead>
          <tr><th colspan="4">Drivers Championship Standings</th></tr>
        </thead>
        <tbody>
          <tr ng-repeat="driver in driversList">
            <td>{{$index + 1}}</td>
            <td>
              <img src="img/flags/{{driver.Driver.nationality}}.png" />
              {{driver.Driver.givenName}}&nbsp;{{driver.Driver.familyName}}
            </td>
            <td>{{driver.Constructors[0].name}}</td>
            <td>{{driver.points}}</td>
          </tr>
        </tbody>
      </table>
    </body>
    

    The first thing you’ll notice in this template is the use of expressions (“{{“ and “}}”) to return variable values. In AngularJS, expressions allow you to execute some computation in order to return a desired value. Some valid expressions would be:

    • {{ 1 + 1 }}
    • {{ 946757880 | date }}
    • {{ user.name }}

    Effectively, expressions are JavaScript-like snippets. But despite being very powerful, you shouldn’t use expressions to implement any higher-level logic. For that, we use directives.

    Understanding Basic Directives

    The second thing you’ll notice is the presence of ng-attributes, which you wouldn’t see in typical markup. Those are directives.
    At a high level, directives are markers (such as attributes, tags, and class names) that tell AngularJS to attach a given behaviour to a DOM element (or transform it, replace it, etc.). Let’s take a look at the ones we’ve seen already:

    • The ng-app directive is responsible for bootstrapping your app defining its scope. In AngularJS, you can have multiple apps within the same page, so this directive defines where each distinct app starts and ends.
    • The ng-controller directive defines which controller will be in charge of your view. In this case, we denote the driversController, which will provide our list of drivers (driversList).
    • The ng-repeat directive is one of the most commonly used and serves to define your template scope when looping through collections. In the example above, it replicates a line in the table for each driver in driversList.

    Adding Controllers

    Of course, there’s no use for our view without a controller. Let’s add driversController to our controllers.js:

    angular.module('F1FeederApp.controllers', []).
    controller('driversController', function($scope) {
        $scope.driversList = [
          {
              Driver: {
                  givenName: 'Sebastian',
                  familyName: 'Vettel'
              },
              points: 322,
              nationality: "German",
              Constructors: [
                  {name: "Red Bull"}
              ]
          },
          {
              Driver: {
              givenName: 'Fernando',
                  familyName: 'Alonso'
              },
              points: 207,
              nationality: "Spanish",
              Constructors: [
                  {name: "Ferrari"}
              ]
          }
        ];
    });
    

    You may have noticed the $scope variable we’re passing as a parameter to the controller. The $scopevariable is supposed to link your controller and views. In particular, it holds all the data that will be used within your template. Anything you add to it (like the driversList in the above example) will be directly accessible in your views. For now, let’s just work with a dummy (static) data array, which we will replace later with our API service.
    Now, add this to app.js:

    angular.module('F1FeederApp', [
      'F1FeederApp.controllers'
    ]);
    

    With this line of code, we actually initialize our app and register the modules on which it depends. We’ll come back to that file (app.js) later on.
    Now, let’s put everything together in index.html:

    <!DOCTYPE html>
    <html>
    <head>
      <title>F-1 Feeder</title>
    </head>
    <body ng-app="F1FeederApp" ng-controller="driversController">
      <table>
        <thead>
          <tr><th colspan="4">Drivers Championship Standings</th></tr>
        </thead>
        <tbody>
          <tr ng-repeat="driver in driversList">
            <td>{{$index + 1}}</td>
            <td>
              <img src="img/flags/{{driver.Driver.nationality}}.png" />
              {{driver.Driver.givenName}}&nbsp;{{driver.Driver.familyName}}
            </td>
            <td>{{driver.Constructors[0].name}}</td>
            <td>{{driver.points}}</td>
          </tr>
        </tbody>
      </table>
      <script src="bower_components/angular/angular.js"></script>
      <script src="bower_components/angular-route/angular-route.js"></script>
      <script src="js/app.js"></script>
      <script src="js/services.js"></script>
      <script src="js/controllers.js"></script>
    </body>
    </html>
    

    Modulo minor mistakes, you can now boot up your app and check your (static) list of drivers.
    Note: If you need help debugging your app and visualizing your models and scope within the browser, I recommend taking a look at the awesome Batarang plugin for Chrome.

  • AngularJS Tutorial: Demystifying Custom Directives – Shared Tutorial

    With the rapid growth of JavaScript as a full stack language, more and more applications are utilizing frameworks that enable the web browser to handle more of the UI processing such as data binding, managing data views, transforming data and many other services. One of the most capable, extensible and popular frameworks is AngularJS, and one of the most useful components of the AngularJS framework is something called a directive. AngularJS provides many useful directives and, even more importantly, it provides a rich framework for creating custom directives.
    What is a directive? To put it simply, directives are JavaScript functions that manipulate and add behaviors to HTML DOM elements. Directives can be very simplistic or extremely complicated. Therefore, getting a solid grasp on their many options and functions that manipulate them is critical.
    In this tutorial, the four functions that execute as a directive is created and applied to the DOM will be explored and examples will be provided. This post assumes some familiarity with AngularJS and custom directives. If you’re newer to Angular, you might enjoy a tutorial on building your first AngularJS app.

    The Four Functions of the AngularJS Directive Life Cycle

    There are many options that can be configured and how those options are related to each other is important. Each directive undergoes something similar to a life cycle as AngularJS compiles and links the DOM. The directive lifecycle begins and ends within the AngularJS bootstrapping process, before the page is rendered. In a directive’s life cycle, there are four distinct functions that can execute if they are defined. Each enables the developer to control and customize the directive at different points of the life cycle.
    The four functions are: compile, controller, pre-link and post-Link.
    The compile function allows the directive to manipulate the DOM before it is compiled and linked thereby allowing it to add/remove/change directives, as well as, add/remove/change other DOM elements.
    The controller function facilitates directive communication. Sibling and child directives can request the controller of their siblings and parents to communicate information.
    The pre-link function allows for private $scope manipulation before the post-link process begins.
    The post-link method is the primary workhorse method of the directive.
    In the directive, post-compilation DOM manipulation takes place, event handlers are configured, and so are watches and other things. In the declaration of the directive, the four functions are defined like this.

    .directive("directiveName",function () {
        return {
          controller: function() {
            // controller code here...
          },
          compile: {
            // compile code here...
            return {
              pre: function() {
                // pre-link code here...
              },
              post: function() {
                // post-link code here...
              }
            };
          }
        }
      })

    Commonly, not all of the functions are needed. In most circumstances, developers will simply create acontroller and post-link function following the pattern below.

    .directive("directiveName",function () {
        return {
          controller: function() {
            // controller code here...
          },
          link: function() {
            // post-link code here...
          }
        }
      })

    In this configuration, link refers to the post-link function.
    Whether all or some of the functions are defined, their execution order is important, especially their execution relative to the rest of the AngularJS application.

    AngularJS Directive Function Execution Relative to other Directives

    Consider the following HTML snippet with the directives parentDir, childDir and grandChildDir applied to the HTML fragment.

    <div parentDir>
      <div childDir>
        <div grandChildDir>
        </div>
      </div>
    </div>

    The execution order of the functions within a directive, and relative to other directives, is as follows:

    • Compile Phase
      • Compile Function: parentDir
      • Compile Function: childDir
      • Compile Function: grandChildDir
    • Controller & Pre-Link Phase
      • Controller Function: parentDir
      • Pre-Link Function: parentDir
      • Controller Function: childDir
      • Pre-Link Function: childDir
      • Controller Function: grandChildDir
      • Pre-Link Function: grandChildDir
    • Post-Link Phase
      • Post-Link Function: grandChildDir
      • Post-Link Function: childDir
      • Post-Link Function: parentDir

    AngularJS Directive Function Explanation: Deep Dive

    The compilation phase occurs first. Essentially, the compile phase attaches event listeners to the DOM elements. For example, if a particular DOM element is bound to a $scope property, the event listener that allows it to be updated with the the value of the $scope property is applied to the DOM element. The process of compilation starts with the root DOM element from which the AngularJS application was bootstrapped and traverses down the branches of the DOM using a depth-first traversal, compiling a parent first then its children all the way down to the leaf nodes.
    Once compilation is complete, directives can no longer be added or removed from the DOM (although there is way around this by directly using the compile service. The next phase is the calling of controllers and pre-link functions for all directives. When the controller is called, the $scope is available and can be used. The$element injected into the controller contains the compiled template but does not include the transcluded child content (transcluded content is the content between the start and end HTML tags on which the directive is applied). By definition, controllers in an MVC pattern simply pass the model to the view and define functions for handling events. Therefore, the controller of a directive should not modify the DOM of the directive for two reasons: it violates the purpose of the controller, and the transcluded child content has not been added to the DOM. So what does a controller do beyond modify the $scope? The controller allows for child directives to communicate with parent directives. The controller function itself should be thought of as a controller object that will be passed into the child directive’s post-link function if the child directive requests it. Therefore, the controller is typically used to facilitate directive communication by creating an object with properties and methods that can be used by its sibling and child directives. The parent directive cannot determine whether a child directive can require its controller, so it is best to limit code in this method to functions and properties that can safely be used by child directives.
    After the controller function, the pre-link function executes. The pre-link function is mysterious to a lot of people. If you read much of the documentation on the Internet and in books, people write that this function is used only in rare circumstances and people will almost never need it. Those same explanations then fail to give an example of a situation where it could be used.
    The pre-link function is really not complicated at all. First, if you review the AngularJS source code you will find an excellent example of the pre-link function: the directive ng-init uses it. Why? It’s simply a great method to execute private code involving the $scope; code that cannot be called by sibling and child directives. Unlike the controller function, the pre-link function is not passed into directives. Therefore, it can be used to execute code that modifies the $scope of its directive. The directive ng-init does exactly this. When the pre-link function for ng-init executes, it simply executes the JavaScript passed into the directive against the directive’s $scope. The result of the execution is available through the $scope’s prototypal inheritance to child directives during their controller, pre-link and post-link function executions but without giving access to those child directives to re-execute the code in the parent’s pre-link function. Also, the directive may need to execute other code not related to the $scope that it wishes to keep private.
    Some experienced AngularJS developers would say this private code could still be placed in the controller and then not called by the child directives. That argument would hold true if the directive will only be used by the original developer who coded it but if the directive is going to be distributed and reused by other developers then encapsulating private code in the pre-link function could be very beneficial. Since developers never know how their directive will be re-used over the course of time, protecting private code from being executed by a child directive is a good approach to directive code encapsulation. I consider it to be a good practice to place directive communication public code in the controller function, and private code in the pre-link function. Like the controller, the pre-link should never do DOM manipulation nor execute a transclude function, since the content for child directives has not been linked yet.
    For each directive, its controller and pre-link function executes before the controller and pre-link function of its child directives. Once the controller and pre-link phase for all directives is complete then AngularJS begins the linking phase, and executes the post-link functions for each directive. The linking phase runs opposite to the compile, controller and pre-link execution flows by starting with the leaf DOM nodes and working its way up to the root DOM node. The post-link DOM traversal follows a mostly depth-first path. As each child directive is linked, its post-link function is executed.
    The post-link function is the function most commonly implemented in custom AngularJS directives. In this function, almost anything reasonable can be done. The DOM can be manipulated (for itself and child elements only), the $scope is available, the controller object for parent directives can be used, transclude functions can be run, etc. However, there are a few limitations. New directives cannot be added to the DOM because they will not be compiled. Additionally, all DOM manipulations must be done using DOM functions. Simply calling the html function on the DOM element and passing in new HTML will remove all of the event handlers added during the compile process. For example, these will not work as expected:

    element.html(element.html());

    or

    element.html(element.html() + "<div>new content</div>");
    

    The code will not cause the HTML to change, but reassigning the string version of the DOM elements will remove all of the event handlers created during the compile process. Typically, the post-link function is used to wire up event handlers, $watches and $observes.
    Once all of the post-link functions are executed, the $scope is applied to the compiled and linked DOM structure, and the AngularJS page comes alive.

  • Basic AngularJS Example, Syntax, calculation

    AngularJS is a JavaScript framework. It can be added to an HTML page with a <script> tag.

    AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions

    In this basic Tutorial you will learn how to add AngularJS and how to use it.
    But before that you must have basic knowledge of:

    • HTML
    • Javascript
    • CSS

    AngularJS is a JavaScript Framework

    AngularJS is a JavaScript framework. It is a library written in JavaScript.
    AngularJS is distributed as a JavaScript file, and can be added to a web page with a script tag:

    https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js

    AngularJS Extends HTML

    AngularJS extends HTML with ng-directives.
    The ng-app directive defines an AngularJS application.
    The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
    The ng-bind directive binds application data to the HTML view.
    Variable syntax:

    Example: {{ Name }} or {{ Age }}

     

    AngularJS Examples

    Simple Hello World:

    <!DOCTYPE html>
    <html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <body>
    <div ng-app="" ng-init="echo='Hello World'">
    <p ng-bind="echo"></p>
    </div>
    </body>
    </html>

     
    Simple Calculation:

    <!DOCTYPE html>
    <html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <body>
    <div ng-app="">
     	<p>Sum: {{ 1 + 2 }}</p>
     	<p>Multiplication: {{ 2 * 10 }}</p>
     	<p>Division: {{ 10 / 2 }}</p>
            <p>Subtract: {{ 10 - 2 }}</p>
    </div>
    </body>
    </html>

     
    Dynamic text binding:

    <!DOCTYPE html>
    <html>
    <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <body>
    <div ng-app="">
    <p>Name: <input type="text" ng-model="myname" placeholder="Type Your name"></p>
    <p>Hi {{myname}}</p>
    </div>
    </body>
    </html>
    

     
    AngularJS filter example using JSON.

  • AngularJS an Introduction of alternative of Jquery

    AngularJS an Introduction of alternative of Jquery

    Why AngularJS is trending now?

    just word “Powered by Google”.

    and in detail: AngularJS is opensource and it is written in JavaScript and maintained by Google, is famously used in the development of single page applications(SPA). These single page applications are web applications or websites that very well suit on a single web page, giving a smooth user experience. By providing the best of services using AngularJS framework, Though AngularJS is known to have a steep learning curve, it remains to be popular amongst developers for several reasons. Once a significant amount of time is spent on mastering AngularJS, development and testing of applications would become simpler.
     
    With this you dont have to de depended on ID and Classes it is work on “ng-controller” and “ng-app”. Its is MVC based javascript framework which ready your complete HTML page and execute {{ }}. It becomes popular because it allowed rapid front-end application development.
    With the use of this framework, a complete client-side solution is provided cohesively. Data binding, basic templating directives, validation, routing, deep linking and reusable components, all come as a set. Furthermore, the features play a major role in its easy usability. Some of them constitute scope, controller, services, filters, directives, templates, routing, etc. Setting aside the security aspect, AngularJS offers many advantages and has risen in its popularity.
    Reasons for the popularity of AngularJS

    • It is possible to structure the source code by following the Model View ViewModel or Model-View-Controller.
    • The two-way data binding greatly lessens the amount of boilerplate code which is written to keep the model and view in agreement.
    • Designers and developers can work parallelly, as HTML is used for templating. While designers can create user interfaces, the developers tie user interface components with data models by using declarative binding syntax.
    • There is no necessity of using observable functions. Page DOM is analyzed, and the bindings are built on element attributes, in addition to AngularJS modifying the page DOM directly.
    • As the AngularJS data models are Plain Old Java Object(POJO), it is simple to change or append properties without any complications.
    • A data-based web app can be built without the need for relying on any other framework or plug-in. The reason being that the framework comes with a complete package.
    • Unit testing is provided, and even the context based communication is supported. In addition, a project of any size can be easily handled.

     
     
    kxglKG0
     
    Learn AngularJS using Examples