Mudanças entre as edições de "Angular"

De BrapciWiki
Ir para navegação Ir para pesquisar
Linha 31: Linha 31:
 
   { path: 'proceedings', loadChildren: () => import('../120_proceddings/proceddings.module').then(m => m.ProceddingsModule)},  
 
   { path: 'proceedings', loadChildren: () => import('../120_proceddings/proceddings.module').then(m => m.ProceddingsModule)},  
 
  ];
 
  ];
 +
 +
/* Arquivo de módulo destino */
 +
const routes: Routes = [
 +
  { path: '', component: MainJournalComponent, children:
 +
    [
 +
        { path: '', component: ProceedingWelcomeComponent },
 +
        { path: 'view/:id', component: ProceddingsViewComponent },
 +
    ]
 +
  } ];
  
 
==Componentes==
 
==Componentes==

Edição das 12h46min de 19 de agosto de 2023

Angular NG Client

Criando projeto

ng new [project name]

Cirar projeto com as rotas

ng new [project name] --routing --defaults

Colocando em produção

ng build
ng build --base-href=/algumacoisa/
==Module==

Criando módulo com rota

ng g m modulo --routing

Lazy-loading

Criando um método para chamar módulos por Lazy Load (Carga sob demanda - Acesso)

/* Dentro do Arquivo routing-module */ import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [

  { path: , component: MainComponent },
  { path: 'v/:id', component: VComponent },
  { path: 'proceedings', loadChildren: () => import('../120_proceddings/proceddings.module').then(m => m.ProceddingsModule)}, 
];

/* Arquivo de módulo destino */

const routes: Routes = [
 { path: , component: MainJournalComponent, children: 
   [
       { path: , component: ProceedingWelcomeComponent },
       { path: 'view/:id', component: ProceddingsViewComponent },
   ]
 } ];

Componentes

Novo componente

ng g c [/modules/brapci/headers/head]

Route - Routas

ng generate module app-routing --flat --module=app

Rotas com ID

constructor(private ActivatedRoute: ActivatedRoute) {}
ngOnInit() {
  this.ActivatedRoute.params.subscribe(
    res=>console.log(res.id,res.name)
  )
  /*********** GET *********/
  this.ActivatedRoute.queryParams.subscribe(
    res=>console.log(res.id,res.name)
  )
}

Rotas TS

constructor(private Router: Router) {}

Redireciona pagina dentro da programação

this.router.navigate(['home']);
this.router.navigate(['/'])

Com reload da Página

this.router.navigateByUrl('/home');

Rotas Ativas

routerLinkActive
[a routerLink="['/home',1]" [routerLinkActive]="['class_active']" [routerLinkActiveOptions]="{exact: true}">Home 1[a]

routerLink

[a routerLink="['/home',1]">Home 1[a]

Nova Inteface

ng g interface /modules/interface/vocabulary

Data Binding

Interpolation (sem espaços)

{ { title } } (HTML)
public title: string="Título" (TS)

Property Binding

<button [disabled]="disableButton">Botão</button> (HTML)
<img [src]="imageCapaURL"> (HTML)
<img src="Predefinição:ImageCapaURL"> (HTML)

Event Binding

<button (click)="calc()">Calcular</button> (HTML)
<button (click)="calc($event)">Calcular</button> (HTML)
public calc(valor: MouseEvent) { (TS)
  console.log(valor) }

Two-way binding

<input ngModel="nome"> (HTML)
Predefinição:Nome (HTML)
public nome="Nome" (TS)

Services

ng g s data/isbn
  • Incluir no app.component (Http)

Formulários

Ciclo de Vida

Cookie

npm install ngx-cookie-service

No módulo de serviço

import { CookieService } from 'ngx-cookie-service';
public ngOnInit(): void
{
  /******************************************************************** */
  public setLibrary(id: string) {
    this.CookieService.set('library', id);
  }

  public getLibrary() {
    if (this.CookieService.check('library')) {
      return this.CookieService.get('library');
    } else {
      return 0
    }
  }
 }

Bootstrap Angular

ng add @ng-bootstrap/ng-bootstrap
npm install bootstrap bootstrap-icons
/* Editar o arquivoi angular.json */
"styles": [
  "node_modules/bootstrap/scss/bootstrap.scss",
  "node_modules/bootstrap-icons/font/bootstrap-icons.css",
  "src/styles.scss"
],
"scripts": [
  "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
]

npm install @ng-bootstrap/ng-bootstrap

Variáveis

public title:string = "Brapci";
public valor:number = 1;
public valido:boolean = true;
public position: { x: number, y: number } = { x: 0, y: 0 };
public date: Data = new Date();
====Array====

public list: Array<{ nome: string, idade: number}> = [

 { nome: "Rene", idade: 53 },
 { nome: "Viviade", idade: 52 },
];

Insere um tiem em uma array

this.list.push({nome: "Nome", idade: 31 });

Remove um item de uma array

this.list.splice(id)

Criar Modulo

ng g m NOME --routing

Funções

Rodando servidor

ng s

Produção

Gerando Build

Angular Material

Instalar:

ng add @angular/material