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
爱奥尼亚-MQTT插件不';在MessageArrived | Angular 8+;离子的_Angular_Ionic Framework_Ionic4_Mqtt_Angular8 - Fatal编程技术网

爱奥尼亚-MQTT插件不';在MessageArrived | Angular 8+;离子的

爱奥尼亚-MQTT插件不';在MessageArrived | Angular 8+;离子的,angular,ionic-framework,ionic4,mqtt,angular8,Angular,Ionic Framework,Ionic4,Mqtt,Angular8,嗨,伙计们,我需要帮助, 所以:我安装了这个: 这就是我的代码: public TOPIC: string[] = ['Tagliavini/OvenStatus/#']; public MQTT_CONFIG: { host: string, port: number, clientId: string, } = { // host: "mqtt.micro-systems.it", // port: 9001, // clientId

嗨,伙计们,我需要帮助, 所以:我安装了这个:

这就是我的代码:

public TOPIC: string[] = ['Tagliavini/OvenStatus/#'];

  public MQTT_CONFIG: {
    host: string,
    port: number,
    clientId: string,
  } = {
    // host: "mqtt.micro-systems.it",
    // port: 9001,
    // clientId: "mqtt",
    host: "192.168.0.171",
    port: 9001,
    clientId: "mqtt",
  };

  ngOnInit() {

    this._mqttClient = this.mqttService.loadingMqtt(this.ConnectionLost, this.MessageArrived, this.TOPIC, this.MQTT_CONFIG);
  }



 MessageArrived(message) {
    console.log(message.payloadString) // this print the correct message
    this.elaborateMessageArrived(message); // this got error when call

  }

  elaborateMessageArrived(message){
    console.log("try to call me");
  }
所以,连接工作得更好,但当我从mqtt broker接收负载时,控制台日志会在控制台上打印好消息,如您所见,但当我调用

this.elaborareMessageArrived(message)
错误是:

{错误代码:5,错误消息:“AMQJS0005E内部错误。错误 消息:this.ela…一个函数,堆栈跟踪:没有可用的错误堆栈“, 重新连接:未定义,uri:“ws://192.168.0.171:9001/mqtt”}错误代码: 5错误消息:“AMQJS0005E内部错误。错误消息: this.detailureMessageArrived不是函数,堆栈跟踪:无错误 堆栈可用“重新连接:未定义的uri: “ws://192.168.0.171:9001/mqtt” 原型:对象

这是不可能的,函数存在,并且与其他方法一起工作,但是当我直接调用MessageArrized内部时,我得到了这个错误,我该如何解决


谢谢

尝试在类上下文中绑定函数,如下所示:

ngOnInit() {

this._mqttClient = this.mqttService.loadingMqtt(this.ConnectionLost, this.MessageArrived.bind(this), this.TOPIC, this.MQTT_CONFIG);
}`
这应该能解决你的问题

bind(this)
的一些文档如下:

bind()最简单的用法是生成一个函数,无论 它被调用,用一个特定的值调用。常见的错误 对于新的JavaScript程序员来说,就是从对象中提取方法, 然后调用该函数并期望它使用原始函数 对象作为它的this(例如,通过在基于回调的代码中使用该方法)。 但是,如果不特别小心,原始对象通常会丢失


尝试在类上下文中绑定函数,如下所示:

ngOnInit() {

this._mqttClient = this.mqttService.loadingMqtt(this.ConnectionLost, this.MessageArrived.bind(this), this.TOPIC, this.MQTT_CONFIG);
}`
这应该能解决你的问题

bind(this)
的一些文档如下:

bind()最简单的用法是生成一个函数,无论 它被调用,用一个特定的值调用。常见的错误 对于新的JavaScript程序员来说,就是从对象中提取方法, 然后调用该函数并期望它使用原始函数 对象作为它的this(例如,通过在基于回调的代码中使用该方法)。 但是,如果不特别小心,原始对象通常会丢失


你需要提供更多的信息。如果没有
详细消息驱动的内部代码
,我们无法帮助您。内部没有代码您是对的。您确实提供了足够的信息:)您需要提供更多信息。如果没有
详细消息驱动的内部代码
,我们无法帮助您。内部没有代码您是对的。您确实提供了足够的信息:)