Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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 如何使用基于布尔值的ngif隐藏/显示独立组件_Javascript_Angular_Angular Ng If - Fatal编程技术网

Javascript 如何使用基于布尔值的ngif隐藏/显示独立组件

Javascript 如何使用基于布尔值的ngif隐藏/显示独立组件,javascript,angular,angular-ng-if,Javascript,Angular,Angular Ng If,当用户单击子组件中的按钮时,我试图显示/隐藏父组件中的元素。我不确定我是做错了什么,还是我的方法完全错了 父组件 你好,世界 再见世界 子组件 子组件.ts文件 show: boolean = false; showHello() { this.show = !this.show; console.log('show', this.show); } 家长: <hello #hello></hello> <p> {{hello.s

当用户单击子组件中的按钮时,我试图显示/隐藏父组件中的元素。我不确定我是做错了什么,还是我的方法完全错了

父组件

你好,世界
再见世界
子组件


子组件.ts文件

show: boolean = false;

showHello() {
    this.show = !this.show;
    console.log('show', this.show);
 }
家长:

<hello #hello></hello>
<p>
  {{hello.show}}
</p>


{{你好,秀}

儿童:

import { Component, Input } from '@angular/core';

@Component({
  selector: 'hello',
  template: `<button (click)="showHello()">
              Show
              </button>`,
  styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent  {
  show: boolean = false;

  showHello() {
      this.show = !this.show;
      console.log('show', this.show);
  }
}
从'@angular/core'导入{Component,Input};
@组成部分({
选择器:“你好”,
模板:`
显示
`,
样式:[`h1{font-family:Lato;}`]
})
导出类HelloComponent{
show:boolean=false;
showHello(){
this.show=!this.show;
console.log('show',this.show);
}
}