请告诉我如何将值从[sub.component.html inputBox]发送到[app.component.ts]。发送数据到Angular的组件
sub.component.html
<input type="text">
sub.component.ts
@Component({
selector: 'app-sub',
templateUrl: './sub.component.html'
})
export class SubComponent{
constructor() { }
}
app.component.html
{{input1}}<br />
{{input2}}
<app-sub></app-sub>
<app-sub></app-sub>
app.component.ts
export class AppComponent {
input1 = '';
input2 = '';
}
将值放在app.component.html中两个[app-sub]的inputBox中。 我想把输入框中的值放入变量input1 & input2中。 我不知道如何。
这会帮助你:https://开头的角度。 io/docs/ts/latest/cookbook/component-communication.html#特别是部分*家长收听儿童活动* :) – Alex