如何解决在Angular中嵌套组件时,可以在应用选择器功能中指定额外的参数吗?
app.routing.module.ts文件
const routes: Routes = [
{path: 'users/:id',component: UsersComponent},];
users.componenet.ts文件
@Component({
selector: 'app-users',templateUrl: './users.component.html',styleUrls: ['./users.component.css'],})
modal.component.ts文件
..............
<div class="modal-body">
<app-users></app-users>
</div>
......
因此,用户组件依赖于输入ID(例如users / 1001),当尝试在模式窗口中使用它时,如何将其输入到我的应用选择器中。
我尝试在其中尝试
解决方法
您不能更改组件选择器。为了满足您的要求,您可能必须再定义一个与路由组件几乎相同的组件。
ChildUserComponent:
172.18.0.1
您的users.componenet.ts
172.19.0.1
您的users.componenet.html
@Component({
selector: 'app-child-user',templateUrl: './child-users.component.html',styleUrls: ['./child-users.component.css'],})
export class ChildUsersComponent {
@Input() userId: string;
}
您的modal.component.html
...
export class UsersComponent implements OnInit {
userId: string;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.userId = this.route.snapshot.params.id;
}
}
您的modal.component.ts
<app-child-user [userId]="userId"></app-child-user>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。