简体   繁体   English

在子组件的 html 文件中访问父组件属性

[英]Access Parent component properties in Child component's html file

I want to access the variable/property declared in Parent component into Child's view.我想将父组件中声明的变量/属性访问到子视图中。 Is it possible?是否可以?

@Component({...})
export class ParentComponent implements OnInit{
  public example: string;
  constructor(){
    this.example = 'display this';
}}

@Component({templateUrl: './child.component.html',})
export class ChildComponent extends ParentComponent implements OnInit{...}

child.component.html子组件.html

< div>{{ example }}< /div> <div>{{例子}}</div>

您可以使用@Input 将数据从父组件传递给子组件,以将父组件属性访问到子组件中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM