Am using ng-bootstrap modal in my application to show dialogue box. but while clicking the button, nothing is happening, the modal is not displaying. while debugging it could find that the action is getting called, but the modal is not showing.
this is my app.module.ts
this is my FeatureComponent class
import { Component, ViewChild,Input } from '@angular/core';
import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';
import {FeatureServices} from '../service/feature.services'
import {ComponentAction} from '../base/Component.action'
import {Features} from '../model/feature'
import { NgForm } from '@angular/forms';
import {NgbModal, NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'addstories',
template: `
<div class="modal-header">
<h4 class="modal-title">Hi there!</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Hello, {{name}}!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="activeModal.close('Close click')">Close</button>
</div>
`
})
export class StoryComponents {
@Input() name;
constructor(public activeModal: NgbActiveModal) {}
}
@Component({
moduleId:module.id,
selector:'feature',
template:`
<link rel="stylesheet" href="../../bower_components/bootstrap/dist/css/bootstrap.min.css">
<div>
<button class="btn btn-primary" (click)="listFeature()">All Features</button>
<button class="btn btn-primary" (click)="showAddFeature()" >Add Features</button>
</div>
{{enableAddFeature}}
<!-- loads child component list task and add new task -->
<router-outlet></router-outlet>
<form *ngIf="mode == 'insert' || mode == 'update' " #featureForm="ngForm" (ngSubmit)="processFeature(featureForm)">
<div class="form-group">
<label for="title">Feature Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Enter Feature Title" [(ngModel)]=selectedFeature.title>
</div>
<div class="form-group">
<label for="descr">Feature Title</label>
<input type="text" class="form-control" id="descr" name="descr" placeholder="Enter Feature Description" [(ngModel)]=selectedFeature.descr>
</div>
<div class="form-group">
<label for="area">Feature Title</label>
<input type="text" class="form-control" id="area" name="area" placeholder="Enter Feature Area" [(ngModel)]=selectedFeature.area>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<br/>
<div class="container">
<div class="row">
<div class="">
<table class="table table-hover table-responsive table-bordered">
<thead>
<tr>
<th class="col-md-2">Title</th>
<th class="col-md-2">Descr</th>
<th class="col-md-1">Area</th>
<th class="col-md-1">User Stories</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let feature of features">
<td><a data-toggle="modal" data-target="#myModal">{{feature.title}}</a></td>
<td>{{feature.descr}}</td>
<td>{{feature.area}}</td>
<td *ngIf ="feature.userstories == null" >0</td>
<td *ngIf ="feature.userstories != null" > {{feature.userstories.length}}</td>
<td><a class='btn btn-info btn-xs' (click)="editFeature(feature._id)"><span class="glyphicon glyphicon-edit"></span> Edit</a> <a (click)="deleteFeature(feature)" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-remove"></span> Del</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<button type="button" class="btn btn-default" (click)="open()">Open me!</button>
`
})
export class FeatureComponent extends ComponentAction{
features:Features[]
mode :string = "start";
isEditMode = false;
selectedFeature: Features;
constructor(private featureService:FeatureServices,private modalService: NgbModal){
super();
this.getFeatures();
}
getFeatures(){
this.featureService.getFeatures()
.subscribe(result => {
console.log('features from mongo :'+JSON.stringify(result))
this.features = result;
console.log('this features :'+JSON.stringify(this.features))
})
}
open() {
console.log('u clicked me');
const modalRef = this.modalService.open(StoryComponents);
modalRef.componentInstance.name = 'World';
console.log('finshed');
}
}
I have a list of features and each feature contains different user stories, so am planning to display the option to add user stories into the future on the modal.but while clicking the StoryComponent is not displaying.
I faced the same problem, the issue was with CSS. When I check the elements of the document, find that the modal elements was created but not showing in the screen. Below css has solved the issue.
.modal-backdrop.fade
{
opacity: 0.5;
}
.modal-open .modal
{
opacity: 1;
}