This project was generated with Angular CLI version 11.1.4.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI Overview and Command Reference page.
ng add @angular/material
ng generate component components/template/header
ou
ng g c components/template/header
Altera a aparência e o comportamento de um elemento, componente ou outra diretiva
@directive({
selector: '[appRed]'
})
export class RedDirective {
constructor(el: ElementRef) {
el.nativeElement.style.color = '#E35E6B'
}
}
<i class="material-icons" appRed>
favorite
</i>
Altera o layout adicionando e removendo elementos da DOM
<form *ngIf="product">
</form>
<ul>
<li *ngFor="let product of products">
{{ product.name }}
</li>
</ul>
<table [dataSource]="products">
</table>
@Component({
selector: 'app-product-read',
templateUrl: './product-read.component.html',
styleUrls: ['./product-read.component.css']
})
export class HeaderComponent implements OnInit {
products: Product[]
}
<button mat-raised-button (click)="createProduct()" color="primary">
Salvar
</button>
@Component({
selector: 'app-product-create',
templateUrl: './product-create.component.html',
styleUrls: ['./product-create.component.css']
})
export class HeaderComponent implements OnInit {
createProduct(): void {
// ....
}
}
Component -> HTML
nome: string;
<input [value]="nome">
Component <- -> HTML
nome: string;
<input [(ngModel)]="nome">
É um template que gera código para instruções complexas.
https://angular.io/guide/schematics
Exemplo: Podemos criar um componente de tabela, que fica responsável de mostrar uma lista de dados, com paginação e ordenação.
ng generate @angular/material:table <nome do componente>