app / app.component.ts(192,17):错误TS2339:属性' init'类型' Intercom'

时间:2018-01-17 08:26:32

标签: javascript html node.js angular intercom

  • 我正在尝试在我的代码库中包含对讲npm包
  • 但我收到了以下错误。
  • 你能告诉我如何解决它。
  • 在下方提供我的代码段

app / app.component.ts(192,17):错误TS2339:属性' init'类型'对讲'

上不存在

https://www.npmjs.com/package/ng-intercom

ngOnInit(): void {

    this.intercom.init({
        app_id: "mobilecode",
        // Supports all optional configuration.
        widget: {
            "activator": "#intercom" 
        }
    });
  • 这里提供完整的代码,因为我的代码库很大

https://hastebin.com/nafocafaze.js

2 个答案:

答案 0 :(得分:1)

在您的app-module中:

import { IntercomModule } from 'ng-intercom';

@NgModule({
  imports: [
    ...
    IntercomModule.forRoot({
      appId: <your_app_id>, // from your Intercom config
      updateOnRouterChange: true // will automatically run `update` on router event changes. Default: `false`
    })
  ...
  ]
})

答案 1 :(得分:1)

我通过使用update()而不是init()来实现它(在1.0.0-beta.11中)。我所做的是更改ngOnInit()

中的行

来自

this.intercom.init({

this.intercom.update({

整个区块将如下所示:

ngOnInit() {
  this.intercom.update({
    app_id: <app_id>,
    // Supports all optional configuration.
    widget: {
      "activator": "#intercom"
    }
  });
}

希望这有帮助!

(另一个quickfix正在降级到1.0.0-beta.10,其中init()确实有效。)