Skip to content

Commit 4c29112

Browse files
committed
Added ng-bootstrap modal, which sends and retrieves ids
1 parent 11f9284 commit 4c29112

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="modal-header">
2+
<h4 class="modal-title">My Modal</h4>
3+
<button type="button" class="close" aria-label="Close" (click)="activeModal.close(this.id)">
4+
<span aria-hidden="true">&times;</span>
5+
</button>
6+
</div>
7+
<div class="modal-body">
8+
<p>Hello World!</p>
9+
</div>
10+
<div class="modal-footer">
11+
<button type="button" class="btn btn-outline-dark" (click)="activeModal.close(this.id)">Close</button>
12+
</div>
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, Input } from '@angular/core';
2+
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
23

34
@Component({
45
selector: 'app-my-modal',
56
templateUrl: './my-modal.component.html',
67
styleUrls: ['./my-modal.component.scss']
78
})
89
export class MyModalComponent implements OnInit {
9-
constructor() { }
1010

11-
ngOnInit(): void { }
11+
@Input() id;
12+
13+
constructor(public activeModal: NgbActiveModal) { }
14+
15+
ngOnInit(): void {
16+
console.log(this.id);
17+
}
18+
1219
}

src/app/modules/home/pages/home.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div id="content">
2+
<button class="btn btn-primary" (click)="openMyModal()">Open Modal</button>
23
<ul>
34
<li *ngFor="let project of projects$ | async">
45
{{ project | json }}

src/app/modules/home/pages/home.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export class HomeComponent implements OnInit {
2929
}
3030

3131
openMyModal() {
32-
// this.modalService.open(MyModalComponent, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
33-
// this.closeResult = `Closed with: ${result}`;
34-
// }, (reason) => {
35-
// this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
36-
// });
32+
const modalRef = this.modalService.open(MyModalComponent);
33+
modalRef.componentInstance.id = 1;
34+
modalRef.result.then((result) => {
35+
console.log(result);
36+
});
3737
}
3838

3939
}

0 commit comments

Comments
 (0)