Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase TypeError:无法读取属性';propName';空的_Firebase_Ionic Framework_Ionic2 - Fatal编程技术网

Firebase TypeError:无法读取属性';propName';空的

Firebase TypeError:无法读取属性';propName';空的,firebase,ionic-framework,ionic2,Firebase,Ionic Framework,Ionic2,我总是会遇到这样的错误: TypeError:无法读取null的属性“propName” 这是我的打字稿 handlu道具ts import { Component } from '@angular/core'; import { IonicPage, ModalController, NavController, NavParams, ActionSheetController } from 'ionic-angular'; import { AlertController } from 'i

我总是会遇到这样的错误:

TypeError:无法读取null的属性“propName”

这是我的打字稿

handlu道具ts

import { Component } from '@angular/core';
import { IonicPage, ModalController, NavController, NavParams, ActionSheetController } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { AngularFireDatabase,FirebaseObjectObservable } from 'angularfire2/database';
import { Subscription } from 'rxjs/Subscription';
import { ConAgentsPage } from '../conagents/conagents';
import { HandluPage } from '../handlu/handlu';

import { PropertyItem } from '../../models/property-item/PropItem.interface';


@IonicPage()
@Component({
  selector: 'page-handlu-prop',
  templateUrl: 'handlu-prop.html',
})
export class HandluPropPage {

propertyItemSubscription: Subscription;
propertyItem = {} as PropertyItem;
propertyItemRef$: FirebaseObjectObservable<PropertyItem>;

  constructor(private database: AngularFireDatabase, 
  private modCtrl: ModalController, 
  public navCtrl: NavController, 
  public navParams: NavParams, 
  public alertCtrl: AlertController) {


  const propertyItemId = this.navParams.get('$key');
    console.log(propertyItemId);

  this.propertyItemRef$ = this.database.object(`Property/${propertyItemId}`).valueChanges();
  this.propertyItemSubscription = 
    this.propertyItemRef$.subscribe( propertyItem => this.propertyItem = propertyItem );
  }

 ionViewWillLeave() {
   this.propertyItemSubscription.unsubscribe();
  }
从'@angular/core'导入{Component};
从“ionic angular”导入{IonicPage、ModalController、NavController、NavParams、ActionSheetController};
从'ionic angular'导入{AlertController};
从“angularfire2/database”导入{AngularFireDatabase,FirebaseObjectObservable};
从'rxjs/Subscription'导入{Subscription};
从“../conagents/conagents”导入{ConAgentsPage};
从“../handlu/handlu”导入{HandluPage};
从“../../models/property item/property.interface”导入{PropertyItem};
@IonicPage()
@组成部分({
选择器:'page handlu prop',
templateUrl:'handlu prop.html',
})
导出类HandluPropPage{
物业项目认购:认购;
propertyItem={}作为propertyItem;
propertyItemRef$:FirebaseObjectObservable;
构造函数(专用数据库:AngularFireDatabase,
私有modCtrl:ModalController,
公共navCtrl:NavController,
公共导航参数:导航参数,
公共警报(Ctrl:AlertController){
const propertyItemId=this.navParams.get(“$key”);
console.log(propertyItemId);
this.propertyItemRef$=this.database.object(`Property/${propertyItemId}`).valueChanges();
this.propertyItemSubscription=
this.propertyItemRef$.subscribe(propertyItem=>this.propertyItem=propertyItem);
}
ionViewWillLeave(){
此.propertyItemSubscription.Unsubscripte();
}
handlu-prop.html(这是我的模板的一部分)

{{propertyItem.propName}

尝试将HTML文件修改为此
{{propertyItem?.propName}

用于检查此元素是否已定义,它可以避免应用程序陷入该错误。

您是否在handlu-prop.js文件中声明了一个propName变量?很抱歉,我对此非常陌生。我在哪里可以找到它?或者它与propertyItemId有关?您必须学习java脚本basics,如果您对此不熟悉。可能与
<h2>{{propertyItem.propName}}</h2>