lang:angular:cli
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| lang:angular:cli [2020/05/08 07:36] – Création avec "Installer une version spécifique" root | lang:angular:cli [2024/10/20 00:34] (Version actuelle) – [Mise à jour] : fix typo root | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====Installation==== | + | =====Installation===== |
| + | |||
| + | ====Base==== | ||
| + | |||
| + | Pour chacune des opérations ci-dessous, ne pas oublier | ||
| + | |||
| + | ng build | ||
| + | |||
| + | ====Mise à jour==== | ||
| + | |||
| + | npm install -g npm@latest | ||
| + | npm --version | ||
| + | npm install -g @angular/ | ||
| + | ng --version | ||
| + | |||
| + | |||
| + | ====Gestion des paquets==== | ||
| + | |||
| + | Ca se passe dans le fichier [[prog: | ||
| ===Installer une version spécifique=== | ===Installer une version spécifique=== | ||
| Ligne 5: | Ligne 23: | ||
| npm install @angular/ | npm install @angular/ | ||
| - | Et ne pas oublier de recompiler | ||
| - | | + | ===Gestion des erreurs de mise à jour=== |
| + | En cas de problème, il est possible d' | ||
| + | |||
| + | * '' | ||
| + | |||
| + | Suite à la mise à jour, j' | ||
| + | |||
| + | =====Modification d'un projet===== | ||
| + | |||
| + | ====Ajouter==== | ||
| + | |||
| + | ====Component (page web)==== | ||
| + | |||
| + | | ||
| + | |||
| + | Ce component pourra être appelé via | ||
| + | |||
| + | < | ||
| + | ====Module==== | ||
| + | |||
| + | Un module est un ensemble de components et d' | ||
| + | |||
| + | ===Routage=== | ||
| + | |||
| + | Définir la jonction entre URL et component. | ||
| + | |||
| + | ng generate module app-routing --flat --module=app | ||
| + | |||
| + | '' | ||
| + | |||
| + | * Modifier le fichier '' | ||
| + | |||
| + | <code typescript> | ||
| + | import { Routes, RouterModule } from ' | ||
| + | import { ContactComponent } from ' | ||
| + | import { NotFoundComponent } from ' | ||
| + | |||
| + | const routes: Routes = [ | ||
| + | { path: ' | ||
| + | { path: ' | ||
| + | ]; | ||
| + | |||
| + | @NgModule({ | ||
| + | imports: [RouterModule.forRoot(routes)], | ||
| + | exports: [RouterModule], | ||
| + | declarations: | ||
| + | }) | ||
| + | </ | ||
| + | |||
| + | <WRAP center round important 60%> | ||
| + | Dans '' | ||
| + | </ | ||
| + | |||
| + | * Ajouter dans le fichier '' | ||
| + | |||
| + | <code xml> | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | * Ajouter dans le fichier de test '' | ||
| + | |||
| + | <code typescript> | ||
| + | import { RouterTestingModule } from ' | ||
| + | |||
| + | TestBed.configureTestingModule({ | ||
| + | imports: [ | ||
| + | RouterTestingModule | ||
| + | ], | ||
| + | declarations: | ||
| + | AppComponent | ||
| + | ], | ||
| + | }).compileComponents(); | ||
| + | </ | ||
| + | |||
| + | ===Lazy load=== | ||
| + | |||
| + | Chargement en différé d'un component. | ||
| + | |||
| + | ng generate module modules/ | ||
| + | ng generate component modules/ | ||
| + | |||
| + | * Ajouter dans le fichier '' | ||
| + | |||
| + | <code xml> | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | * Dans le fichier '' | ||
| + | |||
| + | Enlever manuellement le nouveau module : | ||
| + | |||
| + | <code diff> | ||
| + | -import { ContactComponent } from ' | ||
| + | -import { ContactModule } from ' | ||
| + | ... | ||
| + | | ||
| + | | ||
| + | ... | ||
| + | - ContactComponent, | ||
| + | ... | ||
| + | | ||
| + | ... | ||
| + | - ContactModule, | ||
| + | </ | ||
| + | |||
| + | * Dans le fichier '' | ||
| + | |||
| + | Le chargement du component ne se fait plus au niveau global de l' | ||
| + | |||
| + | <code diff> | ||
| + | -import { ContactComponent } from ' | ||
| + | |||
| + | const routes: Routes = [ | ||
| + | - { path: ' | ||
| + | + path: ' | ||
| + | + loadChildren: | ||
| + | + .then(mod => mod.ContactModule) | ||
| + | + }, | ||
| + | </ | ||
| + | |||
| + | * Dans le fichier '' | ||
| + | |||
| + | Le chargement du component se fait lors du chargement du module contact. | ||
| + | |||
| + | <code diff> | ||
| + | +import { ContactComponent } from ' | ||
| + | ... | ||
| + | | ||
| + | - | ||
| + | + | ||
| + | + | ||
| + | + ], | ||
| + | | ||
| + | | ||
| + | | ||
| + | ], | ||
| + | + | ||
| + | + | ||
| + | + ] | ||
| + | }) | ||
| + | </ | ||
| + | |||
| + | * Dans le fichier '' | ||
| + | |||
| + | Remplacer '' | ||
| + | |||
| + | <code typescript> | ||
| + | import { ContactComponent } from ' | ||
| + | |||
| + | const routes: Routes = [ | ||
| + | { path: '', | ||
| + | ]; | ||
| + | </ | ||
| + | |||
| + | [[https:// | ||
lang/angular/cli.1588916211.txt.gz · Dernière modification : de root
