mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(challenge22): new challenge 22
This commit is contained in:
@@ -2,3 +2,5 @@
|
||||
|
||||
/dist
|
||||
/coverage
|
||||
|
||||
.angular
|
||||
|
||||
@@ -35,6 +35,7 @@ This goal of this project is to help you get better at Angular and NgRx by resol
|
||||
<a href="./apps/styling/README.md"><img src="https://img.shields.io/badge/13-styling-orange" alt="styling"/></a>
|
||||
<a href="./apps/di/README.md"><img src="https://img.shields.io/badge/16-di-red" alt="di"/></a>
|
||||
<a href="./apps/anchor-scrolling/README.md"><img src="https://img.shields.io/badge/21-anchor--scrolling-green" alt="anchor-scrolling"/></a>
|
||||
<a href="./apps/router-input/README.md"><img src="https://img.shields.io/badge/22-router--input-green" alt="router-input"/></a>
|
||||
|
||||
</br>
|
||||
<img src="https://img.shields.io/badge/Typescript--gray?logo=typescript" alt="Typescript"/>
|
||||
|
||||
36
apps/router-input/.eslintrc.json
Normal file
36
apps/router-input/.eslintrc.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"extends": ["../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"rules": {
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "attribute",
|
||||
"prefix": "app",
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
]
|
||||
},
|
||||
"extends": [
|
||||
"plugin:@nx/angular",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
]
|
||||
},
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"extends": ["plugin:@nx/angular-template"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
26
apps/router-input/README.md
Normal file
26
apps/router-input/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
<h1>Router Input</h1>
|
||||
|
||||
> Author: Thomas Laforge
|
||||
|
||||
### Statement
|
||||
|
||||
In this small application, you can pass data though routing to `TestComponent`. v16 of Angular introduiced `RouterInput`. The goal of this exercice is to refactor the code to use the new `RouterInput` strategy.
|
||||
|
||||
### Submitting your work
|
||||
|
||||
1. Fork the project
|
||||
2. clone it
|
||||
3. npm install
|
||||
4. `npx nx serve router-input`
|
||||
5. _...work on it_
|
||||
6. Commit your work
|
||||
7. Submit a PR with a title beginning with **Answer:22** that I will review and other dev can review.
|
||||
|
||||
<a href="https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A22+label%3Aanswer"><img src="https://img.shields.io/badge/-Solutions-green" alt="router-input"/></a>
|
||||
<a href='https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A22+label%3A"answer+author"'><img src="https://img.shields.io/badge/-Author solution-important" alt="router-input solution author"/></a>
|
||||
|
||||
<!-- <a href="{Blog post url}" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/-Blog post explanation-blue" alt="router-input blog article"/></a> -->
|
||||
|
||||
<!-- TODO: you can add your twitter or anything else if you wish -->
|
||||
|
||||
_You can ask any question on_ <a href="https://twitter.com/laforge_toma" target="_blank" rel="noopener noreferrer"><img src="./../../logo/twitter.svg" height=20px alt="twitter"/></a>
|
||||
81
apps/router-input/project.json
Normal file
81
apps/router-input/project.json
Normal file
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "router-input",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/router-input/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:browser",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/router-input",
|
||||
"index": "apps/router-input/src/index.html",
|
||||
"main": "apps/router-input/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/router-input/tsconfig.app.json",
|
||||
"assets": [
|
||||
"apps/router-input/src/favicon.ico",
|
||||
"apps/router-input/src/assets"
|
||||
],
|
||||
"styles": ["apps/router-input/src/styles.scss"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"buildOptimizer": false,
|
||||
"optimization": false,
|
||||
"vendorChunk": true,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true,
|
||||
"namedChunks": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "router-input:build:production"
|
||||
},
|
||||
"development": {
|
||||
"browserTarget": "router-input:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "router-input:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/linter:eslint",
|
||||
"outputs": ["{options.outputFile}"],
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"apps/router-input/**/*.ts",
|
||||
"apps/router-input/**/*.html"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
apps/router-input/src/app/app.component.ts
Normal file
24
apps/router-input/src/app/app.component.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { RouterLink, RouterModule } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [RouterLink, RouterModule, ReactiveFormsModule],
|
||||
selector: 'app-root',
|
||||
template: ` <label for="userName">UserName</label>
|
||||
<input id="userName" type="text" [formControl]="userName" />
|
||||
<label for="testId">TestId</label>
|
||||
<input id="testId" type="number" [formControl]="testId" />
|
||||
<button
|
||||
[routerLink]="'test/' + testId.value"
|
||||
[queryParams]="{ user: userName.value }">
|
||||
Test
|
||||
</button>
|
||||
<button routerLink="/">HOME</button>
|
||||
<router-outlet></router-outlet>`,
|
||||
})
|
||||
export class AppComponent {
|
||||
userName = new FormControl();
|
||||
testId = new FormControl();
|
||||
}
|
||||
7
apps/router-input/src/app/app.config.ts
Normal file
7
apps/router-input/src/app/app.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { appRoutes } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [provideRouter(appRoutes)],
|
||||
};
|
||||
15
apps/router-input/src/app/app.routes.ts
Normal file
15
apps/router-input/src/app/app.routes.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Route } from '@angular/router';
|
||||
|
||||
export const appRoutes: Route[] = [
|
||||
{
|
||||
path: '',
|
||||
loadComponent: () => import('./home.component'),
|
||||
},
|
||||
{
|
||||
path: 'test/:testId',
|
||||
loadComponent: () => import('./test.component'),
|
||||
data: {
|
||||
permission: 'admin',
|
||||
},
|
||||
},
|
||||
];
|
||||
8
apps/router-input/src/app/home.component.ts
Normal file
8
apps/router-input/src/app/home.component.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
template: `<div>Home</div>`,
|
||||
})
|
||||
export default class HomeComponent {}
|
||||
21
apps/router-input/src/app/test.component.ts
Normal file
21
apps/router-input/src/app/test.component.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { AsyncPipe } from '@angular/common';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { map } from 'rxjs';
|
||||
@Component({
|
||||
selector: 'app-test',
|
||||
standalone: true,
|
||||
imports: [AsyncPipe],
|
||||
template: `
|
||||
<div>TestId: {{ testId$ | async }}</div>
|
||||
<div>Permission: {{ permission$ | async }}</div>
|
||||
<div>User: {{ user$ | async }}</div>
|
||||
`,
|
||||
})
|
||||
export default class TestComponent {
|
||||
private activatedRoute = inject(ActivatedRoute);
|
||||
|
||||
testId$ = this.activatedRoute.params.pipe(map((p) => p['testId']));
|
||||
permission$ = this.activatedRoute.data.pipe(map((d) => d['permission']));
|
||||
user$ = this.activatedRoute.queryParams.pipe(map((q) => q['user']));
|
||||
}
|
||||
0
apps/router-input/src/assets/.gitkeep
Normal file
0
apps/router-input/src/assets/.gitkeep
Normal file
BIN
apps/router-input/src/favicon.ico
Normal file
BIN
apps/router-input/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/router-input/src/index.html
Normal file
13
apps/router-input/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>router-input</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
7
apps/router-input/src/main.ts
Normal file
7
apps/router-input/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { AppComponent } from './app/app.component';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||
console.error(err)
|
||||
);
|
||||
1
apps/router-input/src/styles.scss
Normal file
1
apps/router-input/src/styles.scss
Normal file
@@ -0,0 +1 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
10
apps/router-input/tsconfig.app.json
Normal file
10
apps/router-input/tsconfig.app.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"types": []
|
||||
},
|
||||
"files": ["src/main.ts"],
|
||||
"include": ["src/**/*.d.ts"],
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
7
apps/router-input/tsconfig.editor.json
Normal file
7
apps/router-input/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"types": []
|
||||
}
|
||||
}
|
||||
29
apps/router-input/tsconfig.json
Normal file
29
apps/router-input/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"useDefineForClassFields": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.editor.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user