У меня есть следующий код
(теги компонента ts)
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
@Component({
selector: 'app-tags',
templateUrl: './tags.component.html',
styleUrls: ['./tags.component.css']
})
export class TagsComponent implements OnInit{
Tags= [
'red',
'blue',
'purple'
];
red : boolean
blue : boolean
purple : boolean
constructor(private route:ActivatedRoute ) {}
ngOnInit(){
this.Tags= this.route.snapshot.params['name']
this.route.params
.subscribe((params: Params) => {
this.red = this.Tags.includes ('red');
this.purple = this.Tags.includes ('purple');
this.blue = this.Tags.includes ('blue');
}
);
}
}
(HTML-тег компонента)
<ul>
<a><li *ngIf="red">red</li></a>
<a><li *ngIf="blue">blue</li></a>
<a><li *ngIf="purple">purple</li></a>
</ul>
(модуль приложения)
const appRoutes: Routes= [
{path:'', component: AppComponent},
{path:'tags/:name', component: TagsComponent}
];
Прямо сейчас, когда я пишу URL с именем цвета, в элементе списка появится только упомянутый цвет, и это именно то, что я хочу сделать.
пример
![enter image description here](https://i.stack.imgur.com/Saiq5.png)
Теперь все жестко закодировано. Я хочу иметь возможность писать любой другой цвет, которого нет в моем массиве, например зеленый, и обновлять массив и отображать элементы списка соответствующим образом.
Я новичок в этом, поэтому я знаю, что мой вопрос может быть немного базовым, но любая помощь приветствуется
Спасибо