English
Checkpoint
What must work
Run in Source/Chatex.Web:
powershell
npm run buildpowershell
npm test -- --watch=falsepowershell
npm run lintpowershell
npm run format:checkCompare the finished files with the reference:
powershell
git diff --no-index --stat Source/Chatex.Web/src/app/features/auth D:\Work\Chatex-Reference\Source\Chatex.Web\src\app\features\authpowershell
git diff --no-index Source/Chatex.Web/src/app/app.ts D:\Work\Chatex-Reference\Source\Chatex.Web\src\app\app.tsBoth print nothing; so do the comparisons of toast.service.ts, toaster.ts and dialogs.ts. shell.ts, no-chat.page.ts and app.routes.ts grow in the next topics.
Commit:
powershell
git add .powershell
git commit -m "Add sign-in, registration, lazy routes, toasts, dialogs and the responsive shell"Common mistakes
Table 17.2. Common mistakes in routing, forms and layout
| Symptom | Cause | Fix |
|---|---|---|
NG8002: Can't bind to 'formGroup' since it isn't a known property of 'form'. | ReactiveFormsModule is missing in the component's imports | add it |
NG8001: 'router-outlet' is not a known element | RouterOutlet is missing in the component's imports | add it; every standalone component imports what its template uses |
NG5002: @for loop must have a "track" expression | a @for block without track | track by a stable id: track toast.id |
NG5002: Unexpected closing tag "div". in a template with an @ sign | a literal @ opens a control flow block | write @ |
Could not resolve "./features/auth/login" | a wrong path in loadComponent | the file is login.page.ts: import('./features/auth/login.page') |
after signing in, the app always goes to /chats instead of the page the user wanted | returnUrl is not set: withComponentInputBinding() is missing in app.config.ts | add it to provideRouter |
| a dialog appears unstyled at the bottom of the page | the CDK's overlay-prebuilt.css is not in the styles of angular.json | add it before src/styles.css |
Self-check questions
- Why are toasts kept in a root service and rendered by one component in
App? - Why does
ToastServicereplace its array instead of pushing into it? - What does
trackdo in a@forblock, and what would happen without it? - Which problems of dialogs does Angular CDK solve, and what does it leave to us?
- What is content projection? Which C# UI technology has the same idea?
- What is the difference between template-driven forms and Reactive Forms? Why does Chatex use the latter?
- Why does a field show its message only after it was touched? What changes when the user clicks "Sign in"?
- How does a server error such as
user_name_takenend up under the user name field, and when does it disappear? - Why must
returnUrlbe checked before navigating to it? What is an open redirect? - What does lazy loading change in the build output and in the browser?
Exercises
- Show the password. Add an eye button to the password field of the sign-in page that toggles the input's
typebetweenpasswordandtext. Keep it accessible:aria-labelandaria-pressed. - A test for the guard. Write
guards.spec.ts: withfakeAuth(null)provided asAuthService,authGuardmust return aUrlTreeto/login?returnUrl=%2Fsettingsfor the URL/settings. (UseTestBed.runInInjectionContextto call the guard function.) - Toast for the theme. When the user toggles the theme in the shell, show an info toast "Dark theme" or "Light theme". Which service do you inject, and why is no change in
Toasterneeded?