【发布时间】:2019-06-30 19:57:36
【问题描述】:
我想将在 Parent 组件中声明的变量/属性访问到 Child 的视图中。有可能吗?
@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
{{示例}}
【问题讨论】:
-
您是否扩展父母只是为了让孩子拥有
example?如果是,您可以改用@Input来解决您的问题。
标签: angular angular6 angular7 angular-components