[英]How can i make empty component in the child route,from the parent,when i use router outlet
I have a parent route where on click I show content from one child route and in the child route, on click, I fetch different data and I use router-outlet
in the parent component's HTML. 我有一个父路由,单击该按钮时,我显示一个子路由的内容,而在子路由中,单击时,我获取不同的数据,并在父组件的HTML中使用
router-outlet
。 Now I want to empty the div
which was rendered in the child route from the parent ts file based on a condition. 现在我想根据条件从父ts文件中清空在
div
渲染的div
。 Any ideas? 有任何想法吗?
Here is my code 这是我的代码
// Here is the caller method
openRoleSection(roleId: string) {
// Here is the condition, and when it is met, I need to empty the div in the parent route
if (roleId != this.adminServices.serviceRoleId) {
alert("yes")
}
// Here I am calling the parent routes
this.router.navigateByUrl(`adminpanel/specific-role-section/${roleId}`, { relativeTo: this.activatedRoute })
}
<!-- I need to empty this div from the child route -->
<div *ngIf="isViewAllEmployeesButtonClicked">
<div *ngFor="let employee of allUsersFromTheSameRole">
<p>{{ employee }}</p>
</div>
</div>
You can pass a query parameter to the child route on navigation, and use to populate/unpopulate specific information in the child component. 您可以在导航时将查询参数传递给子路径,并用于填充/取消填充子组件中的特定信息。
See https://angular.io/guide/router#query-parameters-and-fragments for more information 有关更多信息,请参见https://angular.io/guide/router#query-parameters-and-fragments
Eg something along the lines of 例如沿着
parent 父母
const params:{
roleId: this.adminServices.serviceRoleId
}
this.router.navigateByUrl(`adminpanel/specific-role-section/${roleId}` , {relativeTo: this.activatedRoute, , queryParams: params})
child 儿童
constructor(route:activatedRoute){
this.roleId= this.route
.queryParamMap
.pipe(map(params => params.get('roleId') || undefined));
}
<div *ngIf="roleId"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.