首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析BsModalService的所有参数

无法解析BsModalService的所有参数
EN

Stack Overflow用户
提问于 2017-08-16 11:12:01
回答 3查看 12.5K关注 0票数 4

我正在向我的spfx angular 2应用程序添加一个模态。我试着通过http://valor-software.com/ngx-bootstrap/#/modals跟踪ngx-bootstrap-modal。但是我得到了这个错误:

代码语言:javascript
复制
Unhandled Promise rejection: Can't resolve all parameters for AppComponent: (?). ; Zone: <root> ; Task: 

下面是我的代码:

package.json

代码语言:javascript
复制
{
  "name": "our-applications",
  "version": "0.0.1",
  "private": true,
  "engines": {
    "node": ">=0.10.0"
  },
  "dependencies": {
    "@angular/common": "^2.4.4",
    "@angular/compiler": "^2.4.4",
    "@angular/core": "^2.4.4",
    "@angular/forms": "^2.4.4",
    "@angular/http": "^2.4.4",
    "@angular/platform-browser": "^2.4.4",
    "@angular/platform-browser-dynamic": "^2.4.4",
    "@angular/router": "^3.4.4",
    "@angular/upgrade": "^2.4.4",
    "@microsoft/sp-client-base": "~1.0.0",
    "@microsoft/sp-client-preview": "~1.0.0",
    "@microsoft/sp-core-library": "~1.0.0",
    "@microsoft/sp-webpart-base": "~1.0.0",
    "@types/webpack-env": ">=1.12.1 <1.14.0",
    "angular2-modal": "^3.0.1",
    "ng2-modal": "0.0.25",
    "ngx-bootstrap": "^1.8.1",
    "reflect-metadata": "^0.1.9",
    "rxjs": "^5.0.3",
    "sp-pnp-js": "^2.0.1",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@microsoft/sp-build-web": "~1.0.0",
    "@microsoft/sp-module-interfaces": "~1.0.0",
    "@microsoft/sp-webpart-workbench": "~1.0.0",
    "@types/chai": "^>=3.4.34 <3.6.0",
    "@types/mocha": ">=2.2.33 <2.6.0",
    "gulp": "~3.9.1"
  },
  "scripts": {
    "build": "gulp bundle",
    "clean": "gulp clean",
    "test": "gulp test"
  }
}

我调用函数的html:

代码语言:javascript
复制
 <button (click)="addApp();" class="ms-Button ms-Button--primary">
            <span class="ms-Button-label">Add Application</span>
        </button>

我的app.component.js代码片段

代码语言:javascript
复制
import { Component, OnInit,ViewEncapsulation, ViewContainerRef } from '@angular/core';
import { AppSettings } from './shared/app.settings';
import { IApplicationEntity } from './shared/app.entities';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class';

export class AppComponent implements OnInit {
    bsModalRef: BsModalRef;

    constructor(private modalService: BsModalService) {}

    public addApp() {
        console.log("open the modal");
        let list = ['Open a modal with component', 'Pass your data', 'Do something else', '...'];
        this.bsModalRef = this.modalService.show(ModalContentComponent);
        this.bsModalRef.content.title = 'Modal with component';
        this.bsModalRef.content.list = list;
    }
}

这是我的app.module.ts

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ModalModule } from 'angular2-modal';
import { BootstrapModalModule } from 'angular2-modal/plugins/bootstrap';
import { AppComponent } from './app.component';
import { AppSettings } from './shared/app.settings';
import { AppLoadingComponent } from './shared/loading/app.loading';
import { AppNotifyComponent } from './shared/notify/app.notify';
import { BsModalService } from 'ngx-bootstrap/modal';


@NgModule({
    imports: [BrowserModule 
    ],
    declarations: [
        AppComponent, 
        AppLoadingComponent,
        AppNotifyComponent],
    bootstrap: [AppComponent],
})

export class AppModule {}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-08-16 13:57:52

在您的app.module.ts中,您没有将ModalModule添加到imports array,解决方案应该是从ngx-bootstrap导入ModalModule并将其添加到您的导入数组中。

代码语言:javascript
复制
import { ModalModule } from 'ngx-bootstrap';
// or
import { ModalModule } from 'ngx-bootstrap/modal';

imports: [BrowserModule, ModalModule.forRoot()],
                         ^^^^^^^^^^^^^^^^^^^^^   mention here

请参阅。

这似乎是一个迟来的答案,但希望它能帮助你解决问题。

票数 14
EN

Stack Overflow用户

发布于 2020-10-31 13:01:24

张贴这篇文章可能会对某些人有所帮助。

如果你在你的应用中创建了不同的NgModules,别忘了在这些模块中导入ModalModule

代码语言:javascript
复制
import { ModalModule } from 'ngx-bootstrap/modal';

@NgModule({
  imports: [    
    ModalModule.forRoot()    
  ],
  declarations: [
    ExampleComponent,    
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class ExampleModule {}
票数 1
EN

Stack Overflow用户

发布于 2017-08-16 12:03:57

快速浏览一下您的代码,我注意到您的AppModule中有用于BSModalService的ES6导入语句,但它没有导入到您的angular AppModule中。如下所示,请将BSModalService添加到AppModule导入中。

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ModalModule } from 'angular2-modal';
import { BootstrapModalModule } from 'angular2-modal/plugins/bootstrap';
import { AppComponent } from './app.component';
import { AppSettings } from './shared/app.settings';
import { AppLoadingComponent } from './shared/loading/app.loading';
import { AppNotifyComponent } from './shared/notify/app.notify';
import { BsModalService } from 'ngx-bootstrap/modal';


@NgModule({
  imports: [BrowserModule, BsModalService 
],
declarations: [
    AppComponent, 
    AppLoadingComponent,
    AppNotifyComponent],
bootstrap: [AppComponent],
})

export class AppModule {}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45704518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档