Skip to main content

IMPORTANT




Following are the key features of Angular 2 

  1. Components 
  2. TypeScript 
  3. Services 
  4. event-handling capabilities
  5. powerful templates,
  6. better support for mobile devices.

  • Modules : Breaks  application into logical pieces of code. 
  • Component: Bring the modules together.
  • Templates: Define the views of an Angular JS application.
  • Metadata: Add more data to an Angular JS class.
  • Service :Create components which can be shared across the entire application.


MODULE 

import { NgModule }      from '@angular/core'; --> IMPORTS FNLTY OF OTHER MODULES
import { BrowserModule } from '@angular/platform-browser';  
import { AppComponent }  from './app.component';  

@NgModule ({ -----> THIS IS DECORATOR
   imports:      [ BrowserModule ],//required by web based application 
   declarations: [ AppComponent ], 
   bootstrap:    [ AppComponent ] //Which component to bootstrap in application
}) 
export class AppModule { } 

  • The NgModule decorator is used to later on define the imports, declarations, and bootstrapping options.
A MODULE CONSISTS OF 

A module is made up of the following parts −
  • Bootstrap array − This is used to tell Angular JS which components need to be loaded so that its functionality can be accessed in the application. Once you include the component in the bootstrap array, you need to declare them so that they can be used across other components in the Angular JS application.
  • Export array − This is used to export components, directives, and pipes which can then be used in other modules.
  • Import array − Just like the export array, the import array can be used to import the functionality from other Angular JS modules.

A component consists of −
  • Class − This is like a class defined in any language such as C. This contains properties and methods. This has the code which is used to support the view. It is defined in TypeScript.
  • class classname {
       Propertyname: PropertyType = Value
    }
  • Metadata − This is used to decorate the class and extend the functionality of the class.
  •  Template − This is used to render the view for the application. This contains the HTML that needs to be rendered in the application. This part also includes the binding and directives.
template: '
   

{{appTitle}}

To Tutorials Point
'
Component
Following is an example of a component.
import { Component } from '@angular/core';

@Component ({ 
   selector: 'my-app', 
   templateUrl: 'app/app.component.html' 
}) 

export class AppComponent { 
   appTitle: string = 'Welcome';
} 
Each application will have a root angular module & others are imported in it.


Following is an example of a root module.

import { NgModule }      from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent }  from './app.component';  

@NgModule ({ 
   imports:      [ BrowserModule ], 
   declarations: [ AppComponent ], 
   bootstrap:    [ AppComponent ] 
}) 
export class AppModule { } 



Following is an example of a component.

import { Component } from '@angular/core';

@Component ({ 
   selector: 'my-app', 
   templateUrl: 'app/app.component.html' 
}) 

export class AppComponent { 
   appTitle: string = 'Welcome';
} 


import { Component } from '@angular/core';

@Component ({
   selector: 'my-app',
   templateUrl: 'app/app.component.html'  
})

export class AppComponent {
   appTitle: string = 'Welcome';
}


*ng-if

import { Component } from '@angular/core';  

@Component ({
   selector: 'my-app',
   templateUrl: 'app/app.component.html'
})

export class AppComponent {
   appTitle: string = 'Welcome';
   appStatus: boolean = true;
}
{{appTitle}} Tutorialspoint

*ng-for


import { Component } from '@angular/core';
 
@Component ({
   selector: 'my-app',
   templateUrl: 'app/app.component.html'
})

export class AppComponent {
   appTitle: string = 'Welcome';
   appList: any[] = [ {
      "ID": "1",
      "Name" : "One"
   },

   {
      "ID": "2",
      "Name" : "Two"
   } ];
}
*ngFor = 'let lst of appList'>
  • {{lst.ID}}
  • {{lst.Name}}

    Metadata is used to decorate a class so that it can configure the expected behavior of the class.

    These are decorators at the class level. This is an array and an example having both the @Component and @Routes decorator


    DATA BINIDNG 

    export class className {
       property: propertytype = value;
    }

















    Comments

    Popular posts from this blog

    The BattleGround

    Last Sunday while zapping the channels of my idiot box I chanced upon to watch one of the greatest epic of our times –MAHABHARAT. It did’nt take me much time to recall the waves that it created across the nation- when it was telecasted for the first time.I was too young to comprehend it,yet I used to watch it with paramount interest,sitting next to dad & imitating his stimuli to what character speaks Later in my teens ,unlike most of my friends who used to enjoy watching top tens & horror shows , I was inundated to discover that zee was going to re telecast Mahabharat .This time, I was grown up enough to understand it,so I religiously watched all the episodes with same interest. Watching such an epic in formative years has great influence on one’s approach towards life .Today to me ,Mahabharat isn’t just another epic but it is a thinking process, where the mind is the battleground, THE KURUSHETRA ,where all kind of thoughts hover, the state of mind that we...

    WHERE THE MIND IS WITHOUT FEAR !

    (Painting By Takshila Vidushi) "Where the mind is without fear & the head is held high Where knowledge is free Where the world hasn't been broken up into fragments By narrow domestic walls Where words come out from the depth of truth Where tireless striving stretches its arms towards perfection ! Where the clear stream of reason has not lost its way Into the dreary desert sand of dead habit Where the mind is led forward by thee Into ever-widening thought and action Into that heaven of freedom, my Father, let my country awake." By Guru RabindraNath Tagore (Ever since childhood this poem of RabindraNath Tagore has been synonmous to supreme level of perfection for me.Its incredibl...

    GraphQL

    What is GraphQL  API Standard invented & open-sourced by Facebook Alternative to  REST API  enables declarative data fetching  exposes single endpoint & responds to queries How it works?  Why Graphql? Improvises performance by reducing the data that is to be transferred over the internet Variety of different frontend frameworks and platforms on client-side Fast development speed & expectation for rapid feature development Why Graphql is better than REST? Flexibility & efficient  No more over /under fetching of data Over fetching : Under fetching: Insightful analytics  Schema serves as contract between client and server CORE CONCEPTS : SDL :SCHEMA DEFINITION LANGUAGE Writing Data with mutations 3 kinds of mutations creating new data updating existing data deleting existing data