www.javascripter.org
Technical Lead
Synerzip Softech India PVT LTD
@pankajparkar
www.javascripter.org
@pankajparkar
www.javascripter.org
@pankajparkar
www.javascripter.org
Angular 1.x = AngularJS
Angular 2+ = Angular
@pankajparkar
www.javascripter.org
@pankajparkar
www.javascripter.org
//`myVariable` holds string value
let myVariable: string = 'Something';
//typescript will throw at compile time error
myVariable = 1;
let myBoolean: bool = true;
@pankajparkar
www.javascripter.org
Component | Data Bindings | Directives |
Services | Templating | Pipes |
Routing | Http Modules | Events |
Testing | Observable | Animation |
Build Tool | Form Modules | Typescript |
@pankajparkar
www.javascripter.org
@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';
}
www.javascripter.org
@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>
www.javascripter.org
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/http';
// required for dependency injection to work
@Injectable({providerIn: 'root'})
export class PostService{
constructor(private http: HttpClient){
}
fetch(){
return this.http.get('https://api.test.com/test.json');
}
}
@Injectable()
@pankajparkar
www.javascripter.org
@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 { }
@pankajparkar
www.javascripter.org
Data Bindings
{{myData}}
Property Binding
[myData]="test"
Event Binding
(eventName)="methodCall($event)"
www.javascripter.org
AppModule
Component
Service
Pipe
Directive
Sub-modules
Exports
NgModule's,
directive's,
component's,etc
Bootstrap root component
@pankajparkar
www.javascripter.org
Three ways to create an Angular App
@pankajparkar
www.javascripter.org
@pankajparkar
www.javascripter.org
@pankajparkar
www.javascripter.org
www.javascripter.org
index.html
<html>
<head>
<link href="style.css" />
<script src="app.bundle.js"></script>
</head>
<body>
<header></header>
<section>
<sidebar></sidebar>
<placeholder></placeholder>
</section>
<footer></footer>
</body>
</html>
URL: #/home
URL: #/about
URL: #/contact
<div>
Home Content
<div>
<div>
About Content
<div>
<div>
Contact Content
<div>
www.javascripter.org
www.javascripter.org
@pankajparkar
www.javascripter.org
@pankajparkar
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