如何解决“错误:数字仅指类型”,用户可以在HTML中包含端口

时间:2019-09-02 11:16:32

标签: typescript cordova ionic-framework types

我开始面向有角度的用户,我尝试将Cordova Mqtt插件和Paho库纳入我的项目中。

我尝试将port: number="";更改为let port: number="";var port: number="";,但是没有用。

我的pages.ts:

...
export class MainpagePage implements OnInit {

  ...
  port: number = "";
  ...

  ngOnInit() {
    var client = new Paho.MQTT.Client(this.url, number.port, this.clientid);
  }
...

错误:

    ERROR in src/app/pages/mainpage/mainpage.page.ts:25:46 - error TS2693: 'number' only refers to a type, but is being used as a value here.

    25  var client = new Paho.MQTT.Client(this.url, number.port, this.clientid);
                                                    ~~~~~~

    [ERROR] An error occurred while running subprocess ng.

    ng run app:ionic-cordova-build --platform=android exited with exit code 1.

我该如何解决这些家伙。预先感谢。

1 个答案:

答案 0 :(得分:3)

number.port应该改为this.port

var client = new Paho.MQTT.Client(this.url, this.port, this.clientid);
//                                          ^^^^

另外port: number = ""是错误的,因为您正在将字符串值("")分配给数字成员变量。您可能想要的是这样的东西:

port: number = 80; // or some other default value for the port