angular - 如何在父组件Angular 7中获取在HTML中处于活动状态的子组件名称
问题描述
我想获取父组件中存在的子组件名称。单击父组件中可用的按钮时,我想知道当前 HTML 中的活动子组件。
父组件 ts 文件
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
active = true;
anyFunction() {
//changing tab status for child
}
}
父组件 html 文件
<div>
<button (click)="anyFunction()"></button>
<app-child1 *ngIf="active"></app-child1>
<app-child2 *ngIf="!active"></app-child2>
</div>
如果我正在显示 child1 组件,那么当我单击我想知道的按钮时,我想获取 Child1Component。应显示 HTML 中的活动项。
解决方案
推荐阅读
- php - 在php中更改页面时安全地保留用户的哈希
- python-3.x - 为什么抓取检测只有 20 个 img 标签?
- javascript - 数据表 - 表隐藏列和顺序
- python-3.x - 在哪里可以找到使用 pycrypto 创建的 PEM 文件
- angular - Angular 6 + Java spring boot:一旦部署的角度路由器无法重新加载页面(刷新)
- git - Azure Devops 构建能否仅获取路径筛选器涵盖的源文件?
- javascript - 带有 HTTP 基本身份验证的 Angular 6 HTTP Get 请求
- sh - 我想删除所有括号值
- php - 在 Laravel 中将数组的第一个字母设为大写
- java - 无法通过 JAVA 对 w REST API 进行 PATCH