单击离子项 - 离子2后无法显示进给数据

时间:2017-01-08 17:27:06

标签: javascript html ionic-framework rss-reader

当我点击主页中我的列表的var SerialPort = require('serialport'); var MYport; SerialPort.list(function (err, ports) { ports.forEach(function(port) { if(port.vendorId == 9999){ console.log('Found It') MYport = port.comName.toString(); console.log(MYport); } }); var port = new SerialPort(MYport, { parser: SerialPort.parsers.readline('\n') }); }); 时,我没有在新页面(DetailPage)中获取Feed的数据。我无法理清我所缺少的,你能帮助我吗?

堆栈:

ion-item

这是我的Runtime Error Error in ./DetailPage class DetailPage - caused by: Cannot read property 'title' of undefined - home.html

home.ts

<ion-header> <ion-navbar color="primary"> <ion-title text-center> App Name </ion-title> </ion-navbar> </ion-header> <ion-content padding> <ion-list> <ion-list inset> <ion-item *ngFor="let entry of entries" (click)="openPage(entry)">{{entry.title}}</ion-item> </ion-list> </ion-list> </ion-content> |--------------------------------------------------------| import { NavController } from 'ionic-angular'; import { Component } from '@angular/core'; import { RssService } from '../../providers/rss-service/rss-service'; import { DetailPage } from '../detail-page/detail-page'; @Component({ selector: 'page-home', templateUrl: 'home.html', providers: [RssService] }) export class HomePage { public entries: any = []; constructor(public rssService:RssService, public nav:NavController) { } ionViewDidLoad(){ this.rssService.load().subscribe( data => { this.entries.push(data); } ); } openPage(entry) { console.log('open page called with ' + entry.title); this.nav.push(DetailPage, {selectedEntry:entry}); } } - detail-page.html

detail-page.ts

1 个答案:

答案 0 :(得分:1)

我认为这是因为条目不在课堂范围内。它只在构造函数中作用域。您可以尝试使用此代码代替DetailPage吗?

import {NavController, NavParams} from 'ionic-angular';
import { Component } from '@angular/core';

@Component({
    templateUrl: 'detail-page.html'
})
export class DetailPage {
    entry:any = {};
    constructor(public nav: NavController, navParams:NavParams) {
        console.log('run');
        this.nav = nav;
        this.entry = navParams.get('selectedEntry');
        console.log('my entry is '+ this.entry.title);
    }
}