Angular Jumpstart
Angular Jumpstart
2
O que é o Angular ?
● Um framework Javascript
3
O que é o Angular ?
● Um framework Javascript
● Open Source
4
O que é o Angular ?
● Um framework Javascript
● Open Source
● Google
5
O que é o Angular ?
● Um framework Javascript
● Open Source
● Google
● Typescript
6
Typescript
● Um superconjunto do Javascript
7
Typescript
● Types
var nome: string = 'Angular';
var idade: number = 17;
var jubilado: boolean = true;
8
Typescript
● Classes
class Person {
first_name: string;
last_name: string;
age: number;
consctructor(){}
greet() {
console.log("Hello", this.first_name);
}
}
9
Typescript
● Interfaces
interface Callback {
(error: Error, data: any): void;
}
10
Typescript
● Decorators
11
Angular CLI
12
Angular CLI
13
Components
14
Components
15
Component
● Anotações
@Component({
selector: 'app-post-list',
})
class PostListComponent {
16
Template
@Component({
selector: 'app-post-list',
template: `
<div class="post-list">
(Uma lista de posts aqui)
</div>`
})
17
Styles
● Adicionando estilos
@Component({
selector: 'app-post-list',
templateUrl: './post-list.component.html',
styleUrls: ['./post-list.component.css']
})
18
Data Binding
● Interpolação
● Property
● Event
● Class
● Style
● Two Way
19
Interpolação
● Apresentando os dados do
componente no template ou
expressões
@Component({
selector: 'app-hello',
template: `<p>Hello, {{name}}!</p>`,
})
export class HelloComponent {
name: string;
constructor() {
this.name = 'World';
}
}
20
Property Binding
<img [src]="heroImageUrl">
<hero-detail [hero]="currentHero"></hero-detail>
21
Event Binding
22
Class Binding
23
Style Binding
24
Directives
● NgIf
● NgFor
● NgSwitch
25
NgIf
<p *ngIf="true">
Expression is true and ngIf is true.
This paragraph is in the DOM.
</p>
<p *ngIf="false">
Expression is false and ngIf is false.
This paragraph is not in the DOM.
</p>
26
NgFor
27
NgSwitch
<div [ngSwitch]="hero?.emotion">
<happy-hero *ngSwitchCase="'happy'" [hero]="hero"></happy-hero>
<sad-hero *ngSwitchCase="'sad'" [hero]="hero"></sad-hero>
<unknown-hero *ngSwitchDefault [hero]="hero"></unknown-hero>
</div>
28
Input
@Component({
selector: 'app-hello',
template: '<p>Hello, {{name}}!</p>',
})
export class HelloComponent {
@Input() name: string;
}
<app-hello name="World"></app-hello>
<app-hello [name]="helloName"></app-hello>
29
Módulo de funcionalidade
● Modularizando o app
@NgModule({
imports: [ CommonModule],
exports: [ CommonModule],
declarations: []
})
export class SharedModule { }
30
Services
31
Dependency Injection
32
Routing
● Roteamento Simples
● Roteamento com módulos
● Módulo de rotas
● Rotas Filhas
33
Roteamento Simples
34
RouterLink
35
Rotas filhas
imports: [RouterModule.forChild(routes)]
36
Dúvidas ?
37