【问题标题】:How to use @output in ionic 3如何在 ionic 3 中使用 @output
【发布时间】:2018-11-22 15:40:12
【问题描述】:

这是父页面

<div>
    <component></component>
<div>

这将重定向到我创建表单的这个组件现在我想获取我在父页面中填写表单的数据 在子页面

<h5> Type of house </h5>
        <ion-item>
            <ion-label stacked> </ion-label>
            <ion-select [(ngModel)]="Type" placeholder="type of house">
                <ion-option value="self"> a </ion-option>
                <ion-option value="got" selected> b </ion-option>
            </ion-select>
        </ion-item>

有一个简单的表格

我知道如何将数据从父级传递给子级,但我不知道如何使用 @output 将数据从子级传递给父级

【问题讨论】:

标签: html angularjs typescript ionic-framework ionic3


【解决方案1】:

child.ts

import {Output, EventEmitter} from '@angular/core';
export class ChildComponent {
  ...
  @Output() typeChanged = new EventEmitter<string>();
  type = "got";

  emit() {
    this.typeChanged.emit(this.type);
  }
}

parent.html

<div>
    <component (typeChanged)="onTypeEmitted($event)"></component>
<div>

parent.ts

export class ParentComponent {
  ...
  onTypeEmitted(type: string) {
    // do something with 'type'
  }
}

其实你可以从angular.io/guide/component-interaction#Parent listens for child event获取。

【讨论】:

    猜你喜欢
    • 2018-03-31
    • 2019-12-10
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多