类型'typeof NgxJsonLdModule'上不存在属性'forRoot'

时间:2018-11-19 08:53:39

标签: angular npm angular-universal

我已经安装了此软件包@ngx-lite/json-ld。为了使我的SEO schema.org动态。按照此Tutorial的指定导入模块时,出现以下错误:

  

src / app / app.module.ts(18,21)中的错误:错误TS2339:类型'typeof NgxJsonLdModule'上不存在属性'forRoot'。

这是我的app.module

import { NgtUniversalModule } from "@ng-toolkit/universal";
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";

// Third Party library
import { NgxJsonLdModule } from "@ngx-lite/json-ld";

import { AppComponent } from "./app.component";
import { AppRoutingModule } from "./app-routing.module";
@NgModule({
  declarations: [AppComponent],
  imports: [
     AppRoutingModule,
     NgtUniversalModule,
     NgxJsonLdModule.forRoot()
  ],
  providers: []
})
export class AppModule {}

我正在使用angular 6.1.9和Angular Universal。

3 个答案:

答案 0 :(得分:2)

此特定程序包(sources here)不提供任何服务,因此在导入时不需要forRoot方法。

您可以像这样导入它:

@NgModule({
  declarations: [AppComponent],
  imports: [
     AppRoutingModule,
     NgtUniversalModule,
     NgxJsonLdModule
  ],
  providers: []
})
export class AppModule {}

答案 1 :(得分:1)

通过在这里查看:

https://github.com/coryrylan/ngx-json-ld/blob/master/lib/ngx-json-ld.module.ts

似乎没有为该模块定义.forRoot()方法,因此正如前面的评论所说的那样,您只需添加模块即可!

祝你好运!

答案 2 :(得分:0)

可以通过.withConfig更改.forRoot

@NgModule({
  imports: [
    ...
    NgxMapboxGLModule.withConfig({
      accessToken: 'TOKEN', // Optional, can also be set per map (accessToken input of mgl-map)
      geocoderAccessToken: 'TOKEN' // Optional, specify if different from the map access token, can also be set per mgl-geocoder (accessToken input of mgl-geocoder)
    })
  ]
})
相关问题