没有CarouselComponent的提供者ngx-boostrap和angular 4 app

时间:2017-10-15 14:53:03

标签: angular bootstrap-4 angular-bootstrap ngx-bootstrap

我试图使用angular-cli让ngx-bootstrap工作角度为4.4.5。 我已按照所有说明操作,我已安装bootstrap 4.0.0-beta以及所有对等依赖项,并且我已正确设置项目。

@NgModule({
  imports: [
    BrowserModule,
    SwingModule,
    HttpModule,
    AppRouterModule,
    FormsModule,
    MultiselectDropdownModule,
    CarouselModule.forRoot() //tried also Ng2BootstrapModule.forRoot()
  ],
  declarations: [
    AppComponent,
    FirstComponent,
    MyOwnComponent,
    YetAnotherComponent
  ],
  providers: [
    {
      'provide': APP_INITIALIZER,
      'useFactory': LookupService.lookupServiceFactory,
      'deps': [LookupService],
      'multi': true
    },
    LookupService, PropertiesService, DefaultApi, CacheService],
  bootstrap: [AppComponent],
})
export class AppModule {
  // Diagnostic only: inspect router configuration
  constructor(router: Router) {
    console.log('Routes: ', JSON.stringify(router.config, undefined, 2));
  }
}

然后我尝试在我的一个自定义组件的模板中使用该组件:

<div class="carousel card-image-top no-gutters">
    <ul class="slides">
      <slide *ngFor="let image of property.ads[0].images">
      <li>
        <img src="{{image}}" alt="">
      </li>
      </slide>
    </ul>
  </div>

我试图为此找到各种解决方案,我尝试了所有来自valor-software的github,但所有解决方案都没有用。

我加载我总是得到同样的错误。

PropertyViewerComponent.html:10 ERROR Error: No provider for CarouselComponent!
    at injectionError (core.es5.js:1169)
    at noProviderError (core.es5.js:1207)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._throwOrNull (core.es5.js:2649)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._getByKeyDefault (core.es5.js:2688)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._getByKey (core.es5.js:2620)
    at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_.get (core.es5.js:2489)
    at resolveNgModuleDep (core.es5.js:9492)
    at NgModuleRef_.webpackJsonp.../../../core/@angular/core.es5.js.NgModuleRef_.get (core.es5.js:10562)
    at resolveDep (core.es5.js:11050)
    at createClass (core.es5.js:10912)

1 个答案:

答案 0 :(得分:1)

似乎我的标签不正确。感谢@yurzui 想念我错过了旋转木马元素。 将html更改为:

<carousel class="carousel card-image-top no-gutters">
    <ul class="slides">
      <slide *ngFor="let image of property.ads[0].images">
      <li>
        <img src="{{image}}" alt="">
      </li>
      </slide>
    </ul>
  </carousel>

解决了它。 这意味着当缺少某个组件时,请确保在html代码中有正确的标签!