ここに私がしようとしていることがあります。親ページコンポーネントのIonic2 popover ngModel値を渡して関数を呼び出しますか?
- Ionic2ポップオーバーメニューにグループラジオボタンを配置します。
- オプションは実際にはコンテンツがどのJSONファイルを読み込むかを制御しています( )。
- ユーザーがオプションを選択し、ポップオーバーを閉じると、コンテンツはページ内でそれに応じて を更新します。
Ionic2 Popoverの値を親コンポーネントに渡す方法がわかりません。私が正しく理解していれば、Ionic2のPopoverは子コンポーネントです。しかし、私はどのように[(ngModel)]
値を渡すか分からない。
私も場合だけ誰かの親切ポップオーバーからページに値を渡す方法の簡単な例を作るために...それはここに乱雑に見えます知っている...
だから... ...このすべて1つのファイルに:
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';
ポップオーバーコンポーネント:
@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;
};
};
別のクラスここでは、ページ:
@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*/
///
}
...ポップオーバーで
...コールバックを渡し、呼び出し側https://plnkr.co/edit/s6lT1a?p=info
をonDismissコールバックを使用した場合の問題 –
コールバックデータはアラートに表示されますが、plnkrの親ページには表示されません。 –
こんにちは@Aron、選択したアイテムをハイライト表示する方法を教えてください。 –