首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >错误产品:无法将属性‘TypeError’设置为null

错误产品:无法将属性‘TypeError’设置为null
EN

Stack Overflow用户
提问于 2018-06-09 06:26:56
回答 1查看 403关注 0票数 0

我正在尝试打印我在前台发送的信息,但我收到了这个错误,我不知道发生了什么,我的查询很好,因为当我在控制台中打印时,它工作正常

错误: https://snag.gy/dAFq4k.jpg

HOME.TS

代码语言:javascript
复制
export class HomePage {
  options:BarcodeScannerOptions;
  encodText:string='';
  resul:string;
  encodedData:any={};
  scannedData:any={};
  public resultado: string;

  public product= [];
  // public product= {};


public resultadoref: firebase.database.Reference = firebase.database().ref('/productos');

  constructor(public fdb: AngularFireDatabase,public navCtrl: NavController,
  public scanner:BarcodeScanner,private alertCtrl: AlertController) {

  }

  public cargarvalor(){
    var referenceresultado= this.resultadoref.orderByChild('Producto').equalTo(this.resultado);
    referenceresultado.on('value', function(snapshot){
    var data = snapshot.val();
    console.log(data);
    // this.product=snapshot.val();
    this.product= snapshot.val();
    });
  }
}

HOME.HTML

代码语言:javascript
复制
<div>

        <ion-input type="text" [(ngModel)]="resultado"></ion-input>
        <button ion-button (click)="cargarvalor()">Buscar</button>


    </div>

        <div class="row header">
          <div class="col">Producto</div>
          <div class="col">Descripcion</div>
          <div class="col">Precio</div>
        </div>

       <div class="row">

        {{ product.Producto }}
        {{ product.Valor }}
        {{ product.Descripcion }}


       </div>
EN

回答 1

Stack Overflow用户

发布于 2018-06-09 07:01:40

this在回调中更改引用。因此,this.product不会引用您的数组。由于回调的调用方式,this实际上是null。

请尝试此修改:

代码语言:javascript
复制
public cargarvalor(){
   var self = this;
   var referenceresultado = this.resultadoref.orderByChild('Producto').equalTo(this.resultado);
   referenceresultado.on('value', function(snapshot) {
      self.product= snapshot.val();
   });
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50769124

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档