Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在我的例子中,如何在angular中切换组件?_Javascript_Angular_Directive - Fatal编程技术网

Javascript 在我的例子中,如何在angular中切换组件?

Javascript 在我的例子中,如何在angular中切换组件?,javascript,angular,directive,Javascript,Angular,Directive,在我的例子中,我试图找到一种在组件之间进行通信的方法 我有一个角度为4的组件,如下所示: my-test.component.ts @Component({ selector: 'my-test', template: `<div> <my-child></my-child> </div>` }) export class MyTestComponent{ } @Component({ selecto

在我的例子中,我试图找到一种在组件之间进行通信的方法

我有一个角度为4的组件,如下所示:

my-test.component.ts

@Component({
    selector: 'my-test',
    template: `<div>
        <my-child></my-child>
    </div>`
})

export class MyTestComponent{
}
@Component({
  selector: 'my-child',
  template: `
      <div *ngIf="show" (click)="toggleMe()">Show this</div>`
})

export class MyChildComponent {
   toggleMe() {
       this.show = !this.show;
   }
}
@组件({
选择器:“我的测试”,
模板:`
`
})
导出类MyTestComponent{
}
my-child.component.ts

@Component({
    selector: 'my-test',
    template: `<div>
        <my-child></my-child>
    </div>`
})

export class MyTestComponent{
}
@Component({
  selector: 'my-child',
  template: `
      <div *ngIf="show" (click)="toggleMe()">Show this</div>`
})

export class MyChildComponent {
   toggleMe() {
       this.show = !this.show;
   }
}
@组件({
选择器:“我的孩子”,
模板:`
展示这个`
})
导出类MyChildComponent{
toggleMe(){
this.show=!this.show;
}
}
我有多个
mytest
组件,每个
mytest
组件都包含一个mychild组件


我的问题是如何确保一次只出现一个
mychild
组件。现在,如果我单击不同的
mychild
组件,它们会不断弹出,但我只希望一次显示一个
mychild
组件。有没有快速的方法可以做到这一点?非常感谢

如何呈现
my test
组件?它们是否隐藏?使用*ngSwitch?@yurzui我的测试默认显示。使用
@Input、@Output
将数据传递到两个组件中,并仅使用一个布尔值进行处理,该布尔值将始终为false,但当您单击特定的子组件时,该布尔值将为true。如何渲染
我的测试
组件?它们是否隐藏?使用*ngSwitch?@yurzui我的测试默认显示。使用
@Input、@Output
将数据传递到两个组件中,并仅使用一个布尔值进行处理,该值将始终为false,但当您单击特定子组件时,该值将为true