Angular 7 + ngx-bootstrap 3.1.3











up vote
3
down vote

favorite












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?










share|improve this question
























  • Have you imported the package module?
    – Sergey
    Nov 9 at 17:23










  • Yes. import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';.
    – Kunyuan Xiao
    Nov 9 at 17:29










  • You're injecting BsModalRef while you should be injecting BsModalService. Check my answer for more details.
    – SiddAjmera
    Nov 9 at 17:49















up vote
3
down vote

favorite












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?










share|improve this question
























  • Have you imported the package module?
    – Sergey
    Nov 9 at 17:23










  • Yes. import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';.
    – Kunyuan Xiao
    Nov 9 at 17:29










  • You're injecting BsModalRef while you should be injecting BsModalService. Check my answer for more details.
    – SiddAjmera
    Nov 9 at 17:49













up vote
3
down vote

favorite









up vote
3
down vote

favorite











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?










share|improve this question















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?







angular ngx-bootstrap angular7 ngx-bootstrap-modal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 16:53









Goncalo Peres

1,3111317




1,3111317










asked Nov 9 at 17:21









Kunyuan Xiao

307




307












  • Have you imported the package module?
    – Sergey
    Nov 9 at 17:23










  • Yes. import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';.
    – Kunyuan Xiao
    Nov 9 at 17:29










  • You're injecting BsModalRef while you should be injecting BsModalService. Check my answer for more details.
    – SiddAjmera
    Nov 9 at 17:49


















  • Have you imported the package module?
    – Sergey
    Nov 9 at 17:23










  • Yes. import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';.
    – Kunyuan Xiao
    Nov 9 at 17:29










  • You're injecting BsModalRef while you should be injecting BsModalService. Check my answer for more details.
    – SiddAjmera
    Nov 9 at 17:49
















Have you imported the package module?
– Sergey
Nov 9 at 17:23




Have you imported the package module?
– Sergey
Nov 9 at 17:23












Yes. import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';.
– Kunyuan Xiao
Nov 9 at 17:29




Yes. import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';.
– Kunyuan Xiao
Nov 9 at 17:29












You're injecting BsModalRef while you should be injecting BsModalService. Check my answer for more details.
– SiddAjmera
Nov 9 at 17:49




You're injecting BsModalRef while you should be injecting BsModalService. Check my answer for more details.
– SiddAjmera
Nov 9 at 17:49












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










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






share|improve this answer























  • It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
    – Kunyuan Xiao
    Nov 9 at 18:39










  • When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
    – Abhishek Ekaanth
    Nov 9 at 19:56


















up vote
0
down vote













According to the docs here, you'll need to inject the BsModalService as a dependency. But you're injecting BsModalRef.



Here's the correct syntax:



import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
...
modalRef: BsModalRef;
constructor(private modalService: BsModalService) {}

openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template);
}


Here's a Working StackBlitz Example for your ref.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230521%2fangular-7-ngx-bootstrap-3-1-3%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    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






    share|improve this answer























    • It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
      – Kunyuan Xiao
      Nov 9 at 18:39










    • When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
      – Abhishek Ekaanth
      Nov 9 at 19:56















    up vote
    2
    down vote



    accepted










    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






    share|improve this answer























    • It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
      – Kunyuan Xiao
      Nov 9 at 18:39










    • When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
      – Abhishek Ekaanth
      Nov 9 at 19:56













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    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






    share|improve this answer














    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







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 9 at 17:50

























    answered Nov 9 at 17:45









    Abhishek Ekaanth

    892923




    892923












    • It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
      – Kunyuan Xiao
      Nov 9 at 18:39










    • When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
      – Abhishek Ekaanth
      Nov 9 at 19:56


















    • It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
      – Kunyuan Xiao
      Nov 9 at 18:39










    • When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
      – Abhishek Ekaanth
      Nov 9 at 19:56
















    It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
    – Kunyuan Xiao
    Nov 9 at 18:39




    It works but why the doc said from 'ngx-bootstrap/modal/bs-modal-ref.service'; and no probiders.
    – Kunyuan Xiao
    Nov 9 at 18:39












    When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
    – Abhishek Ekaanth
    Nov 9 at 19:56




    When ever you're using a service you need to provide them in provider otherwise angular won't be able to understand that it's a service
    – Abhishek Ekaanth
    Nov 9 at 19:56












    up vote
    0
    down vote













    According to the docs here, you'll need to inject the BsModalService as a dependency. But you're injecting BsModalRef.



    Here's the correct syntax:



    import { BsModalService } from 'ngx-bootstrap/modal';
    import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
    ...
    modalRef: BsModalRef;
    constructor(private modalService: BsModalService) {}

    openModal(template: TemplateRef<any>) {
    this.modalRef = this.modalService.show(template);
    }


    Here's a Working StackBlitz Example for your ref.






    share|improve this answer

























      up vote
      0
      down vote













      According to the docs here, you'll need to inject the BsModalService as a dependency. But you're injecting BsModalRef.



      Here's the correct syntax:



      import { BsModalService } from 'ngx-bootstrap/modal';
      import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
      ...
      modalRef: BsModalRef;
      constructor(private modalService: BsModalService) {}

      openModal(template: TemplateRef<any>) {
      this.modalRef = this.modalService.show(template);
      }


      Here's a Working StackBlitz Example for your ref.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        According to the docs here, you'll need to inject the BsModalService as a dependency. But you're injecting BsModalRef.



        Here's the correct syntax:



        import { BsModalService } from 'ngx-bootstrap/modal';
        import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
        ...
        modalRef: BsModalRef;
        constructor(private modalService: BsModalService) {}

        openModal(template: TemplateRef<any>) {
        this.modalRef = this.modalService.show(template);
        }


        Here's a Working StackBlitz Example for your ref.






        share|improve this answer












        According to the docs here, you'll need to inject the BsModalService as a dependency. But you're injecting BsModalRef.



        Here's the correct syntax:



        import { BsModalService } from 'ngx-bootstrap/modal';
        import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';
        ...
        modalRef: BsModalRef;
        constructor(private modalService: BsModalService) {}

        openModal(template: TemplateRef<any>) {
        this.modalRef = this.modalService.show(template);
        }


        Here's a Working StackBlitz Example for your ref.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 17:41









        SiddAjmera

        12.1k21137




        12.1k21137






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230521%2fangular-7-ngx-bootstrap-3-1-3%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()