Angular 2
+
=
Building Blocks
ng2
OUR PARTNERS
Agenda:
mobile and desktop
mobile and
desktop
Advantages :
Quick ng2 Architecture Overview
import {Component} from 'angular2/core';
@Component({
selector: 'hello-world',
template: `<h1>Hello, {{target}}!</h1>`,
styles: [`
h1 {
font-size: 1.2em;
}
`]
})
export class HelloWorldCmp {
target: string;
constructor() {
this.target = 'World';
}
}
highlight.directive.ts
import {Renderer, Directive, ElementRef, Input} from 'angular2/core';
@Directive({
selector: '[myHighlight]'
})
export class HighlightDirective {
constructor(el: ElementRef, renderer: Renderer) {
renderer.setElementStyle(el.nativeElement, 'backgroundColor', 'yellow');
}
}
name_lists.service.ts
export class NameList {
names = ['Dijkstra', 'Knuth', 'Turing', 'Hopper'];
get(): string[] {
return this.names;
}
add(value: string): void {
this.names.push(value);
}
}
di.ts
import {provide, Injector, Injectable} from 'angular2/core';
class Shampoo {}
@Injectable()
class CosmeticShop {
constructor(private shampoo: Shampoo) {
}
}
let injector = Injector.resolveAndCreate([
provide(Shampoo, {useValue: new Shampoo()}),
CosmeticShop
]);
injector.get(CosmeticShop);
letterTransform.pipe.ts
home.ts
import {Pipe} from 'angular2/core';
@Pipe({
name: 'myCustomPipe'
})
export class myCustomPipe {
transform(): string {
// letter formatting
}
}
import {Component} from 'angular2/core';
import {myCustomPipe} from './myCustomPipe.pipe';
@Component({
selector: 'demo-app',
template: '<p>{{longText | myCustomPipe}}</p>',
pipes: [myCustomPipe]
})
export class App {
constructor() {
let longText = 'BANANA-BAANANABANANABANANA-BANANA';
}
}
app.ts
import {Component} from 'angular2/core';
import {
RouteConfig,
ROUTER_DIRECTIVES
} from 'angular2/router';
import {HomeCmp} from '../../home/components/home';
import {AboutCmp} from '../../about/components/about';
@Component({
selector: 'app',
templateUrl: './app.html',
styleUrls: ['./app.css'],
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{path: '/', component: HomeCmp, name: 'Home'},
{path: '/about', component: AboutCmp, name: 'About'},
])
export class AppCmp {}
app.html
<section>
<nav>
<a [routerLink]="['/Home']">What?</a>
<a [routerLink]="['/About']">About</a>
</nav>
<router-outlet></router-outlet>
</section>
Recap :)