Software Engineer
@TSS Consultancy
AngularJS / Angular 1 around 2009
Angular 2 on Sept 2017
Angular 3 skipped
Angular 4 on April 2017
Angular 5 on Nov 2017
Angular X after each six month
Angular 1.x = AngularJS
Angular 2+ = Angular
//`myVariable` holds string value
let myVariable: string = 'Something';
//typescript will throw at compile time error
myVariable = 1;
let myBoolean: bool = true;
Component | Data Bindings | Directives |
Services | Templating | Pipes |
Routing | Http Modules | Events |
Testing | Observable | Animation |
Build Tool | Form Modules | Typescript |
@Component({ metadata })
<body>
<my-app></my-app>
</body>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>
Hello, {{name}}
</h1>`,
styles: [`.body{ margin: auto;}`]
})
export class GreetComopnent {
name: string = 'World';
}
@Directive({ metadata })
import {
Directive, HostListner
} from '@angular/core';
@Directive({
selector: '[myDirective],.myDirective',
})
export class MyDirective {
@HostListner('click', ['$event'])
onClick(event: any) {
console.log(event);
}
}
<div myDirective>
Click Me
</div>
<div class=".myDirective">
Click Me
</div>
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable() // required for dependency injection to work
export class PostService{
constructor(private http: Http){
}
fetch(){
return this.http.get('https://api.test.com/test')
.map(res => res.json());
}
}
@Injectable()
@Pipe({ metadata })
@Pipe({ name: 'isNumber' })
export class IsNumberPipe implements PipeTransform {
transform(n: any) {
return !isNaN(parseFloat(n))
&& isFinite(n);
}
}
<div>
{{'Test' | isNumber }} //Output: false
{{ 1234 | isNumber }} //Output: true
</div>
Value transformation for display purpose
<div>
{{today | date: 'shortDate'}} //Ouput: '10-10-2017'
</div>
Create Custom Pipe
@NgModule({ metadata })
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule ], //other modules or sub-modules
declarations: [ AppComponent ], //components, directives, pipes
bootstrap: [ AppComponent ] //bootstrap component
exports: [] //it can have module,directive,component,pipe,service
})
export class AppModule { }
AppModule
Component
Service
Pipe
Directive
Sub-modules
Exports
NgModule's,
directive's,
component's,etc
Bootstrap root component
Three ways to create an Angular App
Blogs
http://thoughtram.io/
https://johnpapa.net
https://toddmotto.com
https://teropa.info
https://angular.io
https://netbasal.com/@NetanelBasal
https://medium.com/@maximus.koretskyi
Docs
https://angular.io/docs
https://angular.io/api (For API import check)
Best Practices
Coding guidelines by John Papa https://angular.io/guide/styleguide
Books
https://angular-2-training-book.rangle.io/
https://codecraft.tv/courses/angular/
@pankajparkar