Angular pops up two ways

Before we start our blog, we must first install NGX-bootstrap-modal

  NPM Install NGX-bootstrap-modal --save  
Otherwise our modal frame effect will be difficult to see you want to vomit

, pop-up mode (this method is from https://github.com /cipchk/ngx-bootstrap-modal )

(1) DEMO directory

——- -app.component.ts

—— App.Component.html

—— App.Module.ts

——– Detail (folder)

———— Detail.component.ts

———- — Detail.comPonent.html

(2) DEMO code

app.module.ts Import the necessary bootstrapModalModule and ModalModule, register them

// app.module.tsimport {browsermodule} from ‘@ Angular / Platform-Browser’; import {ngmodule} from ‘@ Angular / Core’; // This model box only needs to import Two import {bootstrapmodalmodule} from ‘NGX-bootstrap-modal ‘; import {ModalModule} from’ ngx-bootstrap / modal ‘; import {AppComponent} from’ ./app.component’;import {DetailComponent} from ‘./detail/detail.component’; @ NgModule ({ declarations: [AppComponent, DetailComponent], imports: [BrowserModule, BootstrapModalModule], providers: [], entryComponents: [DetailComponent], bootstrap: [AppComponent]}) export class AppModule {}
   app.Component.html Create a button 

 ALERT Modal frame  
App.comPonent.ts Writing this button Action Showalert ()
Import { Component} from ‘@ Angular / Core’; import {dialogservice} from “ngx-bootstrap-modal”; import {detailcomponent} from’./detail/detail.component’@compoNent ({selector: ‘app-root’, templateURL: ‘./app.component.html’, styleurls: [‘./app.component.css’]ouse )Export class appcomponent {title =’ app ‘; constructor (CONSTRUctor) Public DialogService: DialogService) {} showalert () {this.dialogService.addialog (detailcomponent, {title: ‘alert title!’, message: ‘alert message !!!’});}}

   
×

×
×
  × 
cancel
determined
Detail.comPonent.ts creates an modal box component, we need to create a component, then help boot boot by NGX-Bootstrap-Model
For this component, you need to inherit DialogComponent
, contains two parameters:
T external pass parameters to the type of the modal frame. T1 Modal Frame Return Value Type.
Therefore, DialogService should be DIA parameter of a constructor of AlogComponent.


Import {Component} from ‘@ Angular / Core’; Import {DialogComponent, DialogService} from ‘ngx-bootstrap-modal’; Export Interface AlertModel {Title: String; message: string;} @ Component ({selector: ‘alert’, templateUrl: ‘./detail.component.html’, styleUrls: [ ‘./detail.component.css’]})export class DetailComponent extends DialogComponent

Implements alertmodel {title: string; message: string; constructor (DialogService: DialogService) {super (DialogService);}}

2. Confirm Bark
 (1) Demo directory   -------- App.comPonent.ts  -------- App.component.html 
——– App.Module.ts ——– Confirm (folder)
———— CONFIRM.COMPONENT.TS

———— Confirm.component.hTML (2) DEMO code

App.Module.ts Imports the necessary BootstrapModalModule and ModalModule, then register them, these are the same as the Alert box, because of these Both of the method




// app.module.tsimport {Browsermodule} from ‘@ Angular / Platform-Browser’; import {ngmodule} from ‘@angular / core ‘; // This model box only needs to import the following two import {bootstrapModalModule} from’ ngx-bootstrap-modal ‘; import {modalmodule} from’ ngx-bootstrap / modal ‘; import {appcomponent} from’ ./app.component’;import {DetailComponent} from ‘./detail/detail.component’; @ NgModule ({declarations: [AppComponent, DetailComponent], imports: [BrowserModule, BootstrapModalModule], providers: [], entryComponents: [ DetailComponent], Bootstrap: [AppComponent]}) Export Class AppModule {}

App.Component.html Create a bombButtons of the model frame

Modal Modal frame

   
App.comPonent.ts Write this button Action showconfirm ()

Import {company} from ‘@ Angular / Core’; import { DialogService} from “ngx-bootstrap-modal”; import {ConfirmComponent} from ‘./confirm/confirm.component’@Component ({selector:’ app-root ‘, templateUrl:’ ./app.component.html ‘, styleUrls : [ ‘./app.component.css’]})export class AppComponent {title =’ app ‘; constructor (public dialogService: DialogService, private modalService: BsModalService) {} showConfirm () {this.dialogService.addDialog (ConfirmComponent, {Title: ‘confirmation’, Message: ‘Blal Bla’} .subscribe ((iSconfirmed) => {});}}
  
confirm.component.htmlWrite the layout of the Confirm box
×
{{Title}}

This is the confirm box
 Cancel   determined 

  CONFIRM.Component.ts Create an modal frame component 
Import {company} from '@ angular / core'; import {dialogcomponent, DialogService} from 'NGX- bootstrap-modal '; export interface ConfirmModel {title: string; message: any;} @ Component ({selector:' confirm ', templateUrl:' ./confirm.component.html ', styleUrls: [' ./confirm.component. css']}) export class ConfirmComponent extends DialogComponent
implements ConfirmModel {title: string; message: any; constructor (dialogService: dialogService) {super (dialogService);} confirm () {// on click on conFirm Button We set Dialog Res True, // Ten We Can Get Dialog Result from Caller Code this.close (True);} Cancel () {this.close (false);}}
3. Built-in bomb block
(1) DEMO directory -------- App.component.ts
-------- App.Component.html
-------- App.Module.TS
(2) DEMO code
The built-in bomb also includes three forms of Alert Confirm PROMPT, there are some built-in styles

app.module.ts
   Import {BrowserModule} from '@ angular / platform-browser'; import {NgModule} from '@ angular / core'; import {BootstrapModalModule} from 'ngx-bootstrap-modal'; import {ModalModule} from 'ngx-bootstrap / modal'; import { AppComponent} from './app.component'; @ ngmodule ({Declarations: [AppCompComponent], Imports: [Browsermodule, BootstrapModalModuLe, ModalModule.Forroot ()], Providers: [], Bootstrap: [AppComponent]} (123)  
app.Component.html is simple, One button

built-in



App.component.ts is very simple, even the layout of the component does not write, incoming some parameters such as icon icon, size size, etc.

import {company} from ‘@ Angular / core ‘; import {dialogservice, BuiltinOptions} from “ngx-bootstrap-modal”; @ Component ({selector:’ app-root ‘, templateURL:’ ./app.component.html ‘, Styleurls: [‘ ./ App.Component.css’]}) Export Class Appcomponent {Title = ‘App’; Constructor (Public DialogService: DialogService) {}} {} show () {this.dialogService.show (

{content: ‘Save Success’, icon : ‘Success’, Size: ‘SM’, ShowcancelButton: false}}}
  Second, pop-up mode two  (this method is from https://valor-software.com/ngx-bootstrap/#/modals) 
Still following a method, first install NGX-bootstrap-modal, then import bootstrap style table

1.demo directory

—— App.comPonent.ts ——– App.Component.html
 -------- App.Module.ts  
2. Demo code
// app.module.tsimport {BrowserModule} from ‘@ Angular / Platform-Browser’; import {ngmodule} from ‘@ angular / core’; import {ModalModule} from ‘ngx-bootstrap / modal’; import {AppComponent} from ‘./app.component’; @ NgModule ({declarations: [AppComponent], imports: [BrowserModule, ModalModule. Forroot ()], Providers: [], Entrycomponents: [], bootstrap: [appcomponent]} (123)

APP.Component.ts
 Import {Component, TemplateRef} from '@ Angular / Core'; import {boothModalService} from 'ngx-bootstrap / modal'; import {bsmodalRef} from 'ngx-bootstrap / modal / modal-options.class'; @ Component ({Selector: 'App-root', TemplateURL: './app.component.html', StyleURLS: ['./app.component.css' ]}) export class AppComponent {title = 'app'; public modalRef: BsModalRef; constructor (private modalService: BsModalService) {} showSecond (template: TemplateRef ) {// passed this.modalRef = this is a component .ModalService.show (Template, {Class: 'modal-lg'}); // Show method in BSModalService,};}   
(123)

Second pop-up mode



Second Modal Frame

×

The second modal frame pop-up mode
   
determines

cancel

 Third, the final effect    We will write all the boxes all Then the effect is such a 
Summary

The above is the Angular pop-up modal frame that Xiaobian introduced. In two ways, I hope to help everyone. If you have any questions, please leave a message, Xiaobian will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website!
                    
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment