将Ionic2 popover ngModel值传递给父页面组件并调用函数?

adr*_* li 1 popover typescript ionic2 angular2-ngmodel angular

这就是我想要做的.

  • 将组单选按钮放在Ionic2弹出菜单中.
  • 这些选项实际上是控制内容将加载的JSON文件.
  • 用户选择一个选项,关闭弹出窗口,内容将在页面中相应更新.

我不确定如何将Ionic2 Popover中的值传递给它的父组件.如果我理解正确的话Ionic2的Popover是一个儿童组件.但是我不知道如何传递[(ngModel)]价值.

我知道这里看起来很混乱......好吧,如果只有某人能够做出一个简单的例子来说明如何将值从PopOver传递给Page ...

所以...这一切都在一个文件中:

import {Component, Injectable, Input, Output, EventEmitter} from '@angular/core';
import {ViewController, NavController, Popover, Content, Events, NavParams} from 'ionic-angular';
import {CardService} from '../../providers/card-service/card-service';
import {LangService} from '../../providers/lang-service/lang-service';
import {GlobalService} from '../../providers/global-service';   
Run Code Online (Sandbox Code Playgroud)

Popover组件:

@Component({template: `
    <ion-list  radio-group [(ngModel)]="selected"  (ionChange)="loadc(selected)"> 

        <ion-item  *ngFor="let chapter of menuArray">
            <ion-label>{{chapter.ctitle}}</ion-label>
<ion-radio value="{{chapter.cchap}}" ></ion-radio>
        </ion-item>
    </ion-list>

        `,
    providers: [CardService, LangService, GlobalService],
directives: [LangService]
})

@Injectable()
export class ChapterService{
private chpselected : any;
private menuArray: any;
    constructor(
    private viewCtrl: ViewController,
    private navController: NavController,
    public cardService: CardService,
    public langService: LangService,
    public globalService: GlobalService

    ) {
        this.menuArray = [
    {
                id: 0,
                cchap: '01',
                ctitle: 'One',
        },
    {
                id: 1,
                cchap: '02',
                ctitle: 'Two',
        },
    {
                id: 2,
                cchap: '03',
                ctitle: 'Three',
        },
];
        ///
 this.chpselected = this.menuArray[0]; 

        ///
    };

  close() {
    this.viewCtrl.dismiss();
  }

///-------------------------------
   Here I triggers an even when clicking the radio buttons in the popover. I want to call the loadCards() function in the HomePage class below so it returns what is selected and load the correct JSON in the DOM. However I do not how to pass this loadc() value to loadCards().
///-------------------------------

    loadc(x){
    console.log(x);
        this.globalService.nowchap = x;
    };


};
Run Code Online (Sandbox Code Playgroud)

另一类,页面:

@Component({
  templateUrl: 'build/pages/home/home.html',
    providers: [CardService, LangService, ChapterService, HomePage, GlobalService],
directives: [LangService]
})

@Injectable()
export class HomePage {
///  
public cards;
public viewmode : any;
    constructor(
    private navController: NavController,
    public cardService: CardService,
    public langService: LangService,
    public globalService: GlobalService
    //public chapterService: ChapterService
    ){



    this.viewmode ="read";
        this.loadCards();
    };

    /* POPOVER*/
    presentPopover(myEvent) {
    let popover = Popover.create(ChapterService);
    this.navController.present(popover, {
      ev: myEvent
    });
  }

/* Contents are loading here */
  public loadCards(x){
    console.log("this chp is "+x);
    this.cardService.load(x)
    .then(data => {
      this.cards = data;
    });

  }

/* LOAD CARDS ENDED*/    
///
}
Run Code Online (Sandbox Code Playgroud)

Aar*_*ers 10

不需要服务,只会让事情复杂化..

请在此处查看完整的plunkr - https://plnkr.co/edit/s6lT1a?p=info

它是来电者,通过回调......

 presentPopover(myEvent) {
    let popover = Popover.create(PopoverComponent,{
      cb: function(_data) {
        alert(JSON.stringify(_data))
      }
    });

    this.nav.present(popover, {
      ev: myEvent
    });
  }
Run Code Online (Sandbox Code Playgroud)

在popover ...

constructor(private params: NavParams. /* removed rest for purpose of demo */ ) {
   this.callback = this.params.get('cb')
}

public loadc(x) {

   this.callback(x)

  // Close the popover
  this.close();
}
Run Code Online (Sandbox Code Playgroud)