0

My project angular version:

Angular CLI: 9.0.0-rc.7

I want to show a popup when the page loads.

Isngoninit is run only one time when page loads?

When I log in and then come to the dashboard page why does the popup not open?

The popup does not load. It gives an error in the browser console:

DashboardComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'show' of undefined at DashboardComponent.push../src/app/views/dashboard/dashboard.component.ts.DashboardComponent.ngOnInit

dashboard.component.cs:

import { ModalModule, ModalDirective } from 'ngx-bootstrap/modal';

export class DashboardComponent implements OnInit
{
    @ViewChild('primaryModal') public primaryModal: ModalDirective;

    ngOnInit(): void {

        this.primaryModal.show();
     }

app.module.ts:

import { ModalModule,ModalDirective } from 'ngx-bootstrap';

NgModule({

 ModalModule.forRoot()


  ],

dashboard.component.html

<div bsModal #primaryModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-primary" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Modal title</h4>
                <button type="button" class="close" (click)="primaryModal.hide()" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>One fine body&hellip;</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" (click)="primaryModal.hide()">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

model.directive.d.ts

   ngOnInit(): void;
    /** Allows to manually toggle modal visibility */
    toggle(): void;
    /** Allows to manually open modal */
   public show(): void;
    /** Allows to manually close modal */
    hide(event?: Event): void;

How can I solve this error?

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
raju bhai
  • 37
  • 1
  • 9

0 Answers0