我的app.component.html里有这个链接..。
<a [routerLink]="['system-administration/error-management']">Error Management</a>我希望能够将title属性传递到app组件上的链接到另一个组件,该组件将显示在其html页面上,如下所示.
<h1>{{ title }}</h1>我试过这样做..。
<a [routerLink]="['system-administration/error-management']" [test]="Error Management">Error Management</a>但那不管用。
我发球时犯的错误是.
Can't bind to 'test' since it isn't a known property of 'a'我知道我可以创建一个全局文件并将所有属性放在其中,然后将该全局文件导入到每个组件中,以便以这种方式访问我想要的属性,但我认为,如果我能够简单地传递一个指向组件的链接的属性,那就更简洁了。
这在角11中有可能吗?
提前感谢!
发布于 2022-02-24 20:45:46
您可以在另一个组件的url参数中使用字符串;
import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
@Component({...})
export class MyComponent implements OnInit {
title: string;
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.params.subscribe(params => {
const message = params[0];
this.title = message;
});
}
}https://stackoverflow.com/questions/71257978
复制相似问题