【问题标题】:No Provider for CarouselComponent ngx-boostrap and angular 4 app轮播组件 ngx-bootstrap 和 Angular 4 应用程序没有提供程序
【发布时间】:2017-10-17 15:46:51
【问题描述】:

我正在尝试使用 angular-cli 让 ngx-bootstrap 工作 angular 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)

【问题讨论】:

  • 在哪里注入 CarouselComponent?
  • 我没有注入它,我只是在我的一个组件模板中使用了一个指令。
  • @yurzui 我刚刚添加了模板的 html,希望对您有所帮助。
  • 您的幻灯片应包含在 标记中。你看例子了吗? valor-software.com/ngx-bootstrap/#/carousel
  • 谢谢你这样做:) !!

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


【解决方案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 代码中有正确的标签!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2018-05-27
    • 1970-01-01
    相关资源
    最近更新 更多