【发布时间】:2019-03-11 23:36:57
【问题描述】:
嗨,我想以角度 6 将数据从父母发送给孩子 我的孩子.ts
this.rest.sendRequest('GET', 'station', null).subscribe(
value => {
this.data = value['Station'];
this.source.load(this.data);
console.log(this.data);
},
);
我的父母.ts
addStation() {
this.rest.sendRequest( 'POST', 'station', this.station).subscribe();
}
我的孩子.html
<nb-card>
<nb-card-header>
لیست ایستگاه ها
</nb-card-header>
<nb-card-body>
<ng2-smart-table [getValueFromParent]="value" [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)" (editConfirm)="onEditConfirm($event)">
</ng2-smart-table>
</nb-card-body>
</nb-card>
我的 parent.html 是:
<nb-card>
<nb-card-header>
ایستگاه
</nb-card-header>
<nb-card-body>
<div class="row">
<div class="col-md-4">
<nb-card>
<nb-card-header>
<p>افزودن ایستگاه جدید</p>
</nb-card-header>
<br>
<nb-card-body>
<h3>افزودن ایستگاه</h3>
<form (ngSubmit)="addStation()" #form="ngForm" autocomplete="on" >
<div class="form-control">
<div>
<label for="title">
عنوان
</label>
<input class="form-control" id="title" name="title" nbInput [(ngModel)]="station.title" placeholder="عنوان">
</div>
<div>
<button nbButton type="submit" >افزودن ایستگاه</button>
</div>
</div>
</div>
</form>
</nb-card-body>
</nb-card>
</div>
<div class="col-md-8">
<ngx-smart-table></ngx-smart-table>
</div>
</div>
我想当表单发送我的表格时自动更新我该怎么做?
编辑:我添加了整个 html
我的 this.station 是对象 我的 this.data 是数组
我用过 ng2-smart-table
【问题讨论】:
-
您可以使用
@Input()将数据从父级传递给子级。 -
在哪个组件中?我想要 this.station 发送
-
您要求将数据从父级发送到子级,但您似乎想将数据从子级发送到父级。
-
数据是父级中的this.station,我想将其发送给子级并将其推送到this.data数组
-
但是在你的 parent.html 中,你永远不会使用你的子组件标签。那你怎么能说哪个是孩子或哪个是父母。
标签: angular typescript