title: Angular6: How to open modal from another component
body: <p>I want to open a modal which is belong to a separate component.. I tried it but getting the error <strong>ERROR TypeError: Cannot read property 'show' of undefined</strong> </p>
  
  <p>My code is like below,</p>
  
  <p>product-catalog.component.html</p>
  
  <pre><code>&lt;app-cart-table-modal&gt;&lt;/app-cart-table-modal&gt;
  
  &lt;button type="button" class="btn btn-primary relative waves-light" (click)="basicModal.show(); loadCart(26);" mdbWavesEffect&gt;My Cart&lt;/button&gt;
  </code></pre>
  
  <p>cart-table-modal.component.html</p>
  
  <pre><code>&lt;div mdbModal #basicModal="mdb-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myBasicModalLabel" aria-hidden="true" [config]="{backdrop: false, ignoreBackdropClick: true}"&gt;
    &lt;div class="modal-dialog modal-lg" role="document"&gt;
        &lt;div class="modal-content"&gt;
            &lt;div class="modal-header"&gt;
                &lt;button type="button" class="close pull-right" aria-label="Close" (click)="basicModal.hide()"&gt;
                    &lt;span aria-hidden="true"&gt;×&lt;/span&gt;
                &lt;/button&gt;
                &lt;h4 class="modal-title w-100" id="myModalLabel"&gt;
                    &lt;i class="fa fa-cart-arrow-down fa-4x" aria-hidden="true"&gt;&lt;/i&gt;
                    My Cart
                &lt;/h4&gt;
            &lt;/div&gt;
            &lt;div class="modal-body"&gt;
                &lt;!-- &lt;table class="table table-sm table-striped"&gt; --&gt;
                &lt;table class="table table-striped"&gt;
                    &lt;thead class="mdb-color darken-3"&gt;
                      &lt;tr class="text-white"&gt;
                        &lt;th&gt;#&lt;/th&gt;
                        &lt;th&gt;Product&lt;/th&gt;
                        &lt;th&gt;Model&lt;/th&gt;
                        &lt;th&gt;quantity&lt;/th&gt;
                        &lt;th&gt;Unit Price&lt;/th&gt;
                        &lt;th&gt;Discount&lt;/th&gt;
                        &lt;th&gt;Total&lt;/th&gt;
                        &lt;th&gt;Action&lt;/th&gt;
                      &lt;/tr&gt;
                    &lt;/thead&gt;
                    &lt;tbody&gt;
                        &lt;tr *ngFor="let cartitem of cartitems; let i = index"&gt;
                            &lt;td&gt;
                                &lt;div class="checkbox"&gt;
                                    &lt;label&gt;&lt;input type="checkbox" (change) = "checkMarkCartitem(cartitem.cartItemId)"&gt;{{i+1}}&lt;/label&gt;
                                &lt;/div&gt;
                            &lt;/td&gt;
                            &lt;td&gt;{{cartitem.description}}&lt;/td&gt;
                            &lt;td&gt;{{cartitem.modelNo}}&lt;/td&gt;
                            &lt;td&gt;&lt;input type="number" class="form-control" (blur)="changequantity(cartitem.productId)" 
                                value="{{cartitem.orderQuanity}}" size="16" [id]="'quantity' + cartitem.productId"&gt;&lt;/td&gt;
                            &lt;td&gt;{{cartitem.unitPrice}}&lt;/td&gt;
                            &lt;td&gt;{{cartitem.discountApplied}}&lt;/td&gt;
                            &lt;td&gt;{{cartitem.totalItemAmountIncDiscount}}&lt;/td&gt;
                            &lt;td&gt;
                              &lt;div class="btn-group"&gt;
                                &lt;button type="button" style="background-color: white"&gt;&lt;i class="fa fa-close" 
                                style="font-size:24px;color:red"&gt;&lt;/i&gt;&lt;/button&gt;
                               &lt;/div&gt;     
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td colspan="6"&gt;Total&lt;/td&gt;
                            &lt;td&gt;{{orderTotalAmount}}&lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;/tbody&gt;
                  &lt;/table&gt;
            &lt;/div&gt;
            &lt;div class="modal-footer"&gt;
                &lt;button type="button" class="btn btn-secondary waves-light" aria-label="Close" (click)="basicModal.hide()" mdbWavesEffect&gt;Close&lt;/button&gt;
                &lt;button type="button" class="btn btn-primary relative waves-light" mdbWavesEffect (click) = "placeOrder();"&gt;Place Order&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Any help would be highly Appreciated.. Thanks in Advance..</p>