【问题标题】:Get array from key in URL从 URL 中的键获取数组
【发布时间】:2023-03-23 11:23:01
【问题描述】:

我有一个类似的元素:

temp = new NewsElement('2', 'Überschrift', 'Inhalt', 'schoenesBild');
temp.addChapter('Kap1Überschrift', 'Kapitel1Inhalt');
temp.addChapter('Kap2Überschrift', 'Kapitel2Inhalt');
this.news[temp.key] = temp;

我想通过 url 键建立一个网站:

localhost:4200/test?topic=2

项目是用 Angular 编写的。

【问题讨论】:

  • 你试过带参数的角度路由吗??

标签: html arrays angular url


【解决方案1】:

首先在构造函数中获取查询参数

topic: string;
constructor(private route: ActivatedRoute) {
    console.log('Called Constructor');
    this.route.queryParams.subscribe(params => {
        this.topic= params['topic'];
    });
}

然后使用它

this.news[this.topic] = temp;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-25
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多