【发布时间】:2019-05-09 01:26:15
【问题描述】:
我尝试学习 Angular,现在我处于 @Input 阶段。
我有一个主应用程序和一个子组件。在app.component.ts 我有一个测试变量。我想将此变量从app.component.ts 传递给child.component.ts。
// app.component.ts:
export class AppComponent {
test = 10;
}
// child.component.ts:
export class ChildComponent {
@Input() fromParent: number;
childVar = fromParent + 5;
show() {
console.log(this.childVar);
} //this should to show 15 in console...
}
现在,我该怎么做?
【问题讨论】:
-
这样不行,请阅读文档:angular.io/guide/component-interaction
标签: angular typescript input angular7 angular8