Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use bootstrap alerts? #36

Closed
kamal0808 opened this issue Nov 28, 2017 · 5 comments
Closed

How to use bootstrap alerts? #36

kamal0808 opened this issue Nov 28, 2017 · 5 comments

Comments

@kamal0808
Copy link

Your current documentation shows how to use bootstrap alerts with Jquery only. How can they be used in Angular2+?

@hozjanmarko
Copy link

Do it the angular way... Make a component for a modal
import { Component, ViewChild, Input, TemplateRef } from '@angular/core';
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';

@component({
selector: 'ngx-modal',
templateUrl: './ngx-modal.component.html',
styleUrls: ['./ngx-modal.component.scss']
})
export class NgxModalComponent {
@ViewChild('modal')
protected modal: TemplateRef;
public Title: string;
public Content: string;

protected Visible: Boolean = false;

protected Show(options: ngxModalOption, modalClass: string): BsModalRef {
this.Title = options.Title;
this.Content = options.Content;

this.Visible = true;
this.modalRef = this.modalService.show(this.modal, { class: modalClass });
return this.modalRef;

}

@input()
public ShowWarning(options: ngxModalOption): BsModalRef {
return this.Show(options, "modal-dialog modal-lg modal-warning");
}

@input()
public ShowSucess(options: ngxModalOption): BsModalRef {
return this.Show(options, "modal-dialog modal-lg modal-success");
}

@input()
public ShowDaneger(options: ngxModalOption): BsModalRef {
return this.Show(options, "modal-dialog modal-lg modal-danger");
}

@input()
public ShowInfo(options: ngxModalOption): BsModalRef {
return this.Show(options, "modal-dialog modal-lg modal-info");
}

@input()
public ShowPrimary(options: ngxModalOption): BsModalRef {
return this.Show(options, "modal-dialog modal-lg modal-primary");
}

@input()
public Close() {
if (this.Visible)
this.modalRef.hide();
}

modalRef: BsModalRef;

constructor(private modalService: BsModalService) { }
}

export interface ngxModalOption {
Title: string;
Content: string;
}
<ng-template #modal>

{{Title}}

×

{{Content}}

close

@hozjanmarko
Copy link

I was writimg this on a phone :p

@kamal0808
Copy link
Author

@hozjanmarko Is this code gonna generate modals or notification alerts?

@hozjanmarko
Copy link

Modals... If are looking for a notification service, you could use ng2-toasty, dont forget to add the css of the package to the styles sectio of angular cli json

@kamal0808
Copy link
Author

Thanks, I'm going with https://github.com/scttcper/ngx-toastr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants