angular

Synopsis

Angular is an application-design framework and development platform for creating efficient and sophisticated single-page apps.

Angular Binding:

SyntaxDescription
<p>{{expression}}</p>Interpolation
<p [property]="expression"></p>Property binding
<p>title</p>One-way binding [No changes were reflected in the component]
<input [(ngModel)]="expression">Two-way binding
<p bind-property="expression"></p>Property binding
<p on-event="statement"></p>Event binding
<button [attr.a­ri­a-l­abe­l]=­"­ok">­Ok<­/bu­tto­n>Attribute binding
<p bind-innerHTML="htmlExp"></p>HTML binding
<p [style.color]="colorExp">...</p>Style binding
<p [class.special]="isSpecial">...</p>Class binding
<p [ngClass]="{class­-­1:­co­nd­it­ion­1, class­-­2:­co­nd­it­ion­2}">...</p>Class binding with ngClass
<student-details [student]="currStudent"></student-details>Component binding
<div [ngClass] = "­{se­lected: isSele­cte­d}">­Student<­/di­v>Directive Binding
<div [ngSwitch]="switchExpression">Structural Directive
<input [value]="student.name" (input)="student.name=$event.target.value">$event

Angular Lifecycle Hooks:

Lifecycle HookDescription
ngOnInit()It get invoked when angular initialize component or directive.
ngOnChanges()It get invoked when angular sets data bound input property i.e. @Input().
ngDoCheck()It get invoked for every changes.
ngAfterContentInit()It get invoked after angular project content in its view.
ngAfterContentChecked()It get invoked after angular checks the binding of content into view.
ngAfterViewInit()It get invoked after angular create component view.
ngAfterViewChecked()It get invoked after angular checks the binding of component view.
ngOnDestroy()It get invoked before angular destroy component or directives.

Angular CLI commands:

CommandDescription
ng new project-nameTo create a new project
ng g component To generate a component
ng g directive To generate directive
ng g pipe To generate pipe
ng g service To generate service
ng g class To generate class
ng g interface To generate interface
ng serveTo run application in local server
ng build [—e=]To create a build and change environment
ng testTo test your application
ng e2eTo test your application
ng generate universal [options]To generate universal command
ng g universal [options]To generate universal command
ng addAdds support for an external library
ng updateUpdates workspace and its dependencies
ng versionOutputs Angular CLI version