Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 7 + ngx-bootstrap 3.1.3

Here is a blank angular 7 project in stackblitz, in Angular 6 I used constructor(private bsModalRef: BsModalRef) so I can pass values to my child popup component.

But when I update to angular 7, it said Module not found: Error: Can't resolve 'ngx-bootstrap/modal/bs-modal-ref.service'.

In stackblitz, it asked me to install ngx-bootstrap but I already installed.

Any idea?

like image 355
Kunyuan Xiao Avatar asked Nov 09 '18 17:11

Kunyuan Xiao


2 Answers

First thing is you need to change your import in app.component.ts from

import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';

to

import { BsModalRef } from 'ngx-bootstrap';

then you will have to provide providers in app.module

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap';

import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
import { ModalModule } from 'ngx-bootstrap/modal';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';

@NgModule({
  imports:      [ BrowserModule, FormsModule,ModalModule.forRoot(),
  BsDropdownModule.forRoot() ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ],
  providers: [BsModalRef]
})
export class AppModule { }

working STACKBLITZ

like image 81
Abhishek Ekaanth Avatar answered Sep 28 '22 00:09

Abhishek Ekaanth


Please

import {BsModalRef} from 'ngx-bootstrap/modal/bs-modal-ref.service'

and inject the BsModalService as a dependency.

like image 45
Shilpa Soni Avatar answered Sep 28 '22 01:09

Shilpa Soni