이 글은 Angular에서 모달 상자를 팝업하는 두 가지 방법을 주로 소개합니다. 매우 훌륭하고 참고할 가치가 있습니다. 필요한 친구들이 모두 참고할 수 있기를 바랍니다.
블로그를 시작하기 전에 먼저 ngx-bootstrap-modal을 설치해야 합니다
npm install ngx-bootstrap-modal --save
그렇지 않으면 모달 박스 효과가 보기 어렵고 토하고 싶을 것입니다
1. 팝업 방법 1(이 방법은 다음에서 따옴) https://github.com/cipchk/ngx-bootstrap-modal)
1.alert 팝업 상자
(1)demo 디렉터리
---------app.comComponent.ts
- ------- app.comComponent.html
---------app.module.ts
---------세부정보(폴더)
--------- -----detail .comComponent.ts
------------detail.comComponent.html
(2)데모 코드
app.module.ts 필요한 BootstrapModalModule 및 ModalModule을 가져옵니다. 그런 다음 등록하세요
//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'; import { DetailComponent } from './detail/detail.component'; @NgModule({ declarations: [ AppComponent, DetailComponent ], imports: [ BrowserModule, BootstrapModalModule ], providers: [], entryComponents: [ DetailComponent ], bootstrap: [AppComponent] }) export class AppModule { }
app.comComponent.html 모달 상자를 팝업할 수 있는 버튼을 만듭니다
<p> </p><p> <button>alert模态框</button> </p>
app.comComponent.ts 이 버튼의 동작을 작성합니다. 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'] }) export class AppComponent { title = 'app'; constructor(public dialogService: DialogService) { } showAlert() { this.dialogService.addDialog(DetailComponent, { title: 'Alert title!', message: 'Alert message!!!' }); } }
detail.comComponent.html 레이아웃 작성 경고 팝업 상자
<p> </p><p> </p><p> <button>×</button> </p><h4 id="title">{{title}}</h4> <p> 这是alert弹框 </p> <p> <button>取消</button> <button>确定</button> </p>
detail.comComponent .ts의 모달 상자 구성 요소를 만들려면 구성 요소를 만들어야 하며, 그런 다음 ngx-bootstrap-model이 시작을 안내하는 데 도움이 됩니다
이 구성 요소의 경우 상속해야 합니다. 두 개의 매개변수를 포함하는 DialogComponent
T 모달 상자 유형에 전달되는 외부 매개변수.
T1 모달 상자 반환 값 유형.
따라서 DialogService는 DialogComponent의 생성자 매개변수여야 합니다.
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<alertmodel> implements AlertModel { title: string; message: string; constructor(dialogService: DialogService) { super(dialogService); } }</alertmodel>
2.팝업 상자 확인
(1)데모 디렉토리
---------app.comComponent.ts
---------app.comComponent.html
--- -- ---app.module.ts
---------confirm(폴더)
------------confirm.comComponent.ts
--------- - ---confirm.comComponent.html
(2)demo code
app.module.ts는 필요한 BootstrapModalModule 및 ModalModule을 가져온 다음 경고 팝업 상자와 동일하므로 등록합니다. 방법 1의 팝업 방법
//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'; import { DetailComponent } from './detail/detail.component'; @NgModule({ declarations: [ AppComponent, DetailComponent ], imports: [ BrowserModule, BootstrapModalModule ], providers: [], entryComponents: [ DetailComponent ], bootstrap: [AppComponent] }) export class AppModule { }
app.comComponent.html 모달 상자를 팝업할 수 있는 버튼 만들기
<p> </p><p> <button>modal模态框</button> </p>
app.comComponent.ts 이 버튼의 showConfirm() 액션을 작성하세요
import { Component } 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: 'bla bla' }) .subscribe((isConfirmed) => { }); } }
confirm.comComponent .html 확인 팝업 상자의 레이아웃 작성
<p> </p><p> </p><p> <button>×</button> </p><h4 id="title">{{title}}</h4> <p> 这是confirm弹框 </p> <p> <button>取消</button> <button>确定</button> </p>
verify.comComponent.ts는 모달 상자 구성 요소를 생성합니다
import { Component } 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<confirmmodel> implements ConfirmModel { title: string; message: any; constructor(dialogService: DialogService) { super(dialogService); } confirm() { // on click on confirm button we set dialog result as true, // ten we can get dialog result from caller code this.close(true); } cancel() { this.close(false); } }</confirmmodel>
3. 내장 팝업 상자
(1)데모 디렉터리
---- ---app.comComponent.ts
------ -app.comComponent.html
---------app.module.ts
(2)데모 코드
내장 팝업 상자에는 세 가지 형태의 경고 확인 프롬프트도 포함되어 있으며 모두 일부 내장 스타일이 있습니다
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: [ AppComponent ], imports: [ BrowserModule, BootstrapModalModule, ModalModule.forRoot() ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
app.comComponent.html은 매우 간단합니다. 단 하나의 버튼
<p> </p><p> <button>内置</button> </p>
app.comComponent.ts입니다. 매우 간단합니다. 구성 요소의 레이아웃을 작성할 필요도 없으며 아이콘, 크기 등과 같은 일부 매개변수만 전달하면 됩니다.
import { Component } 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(<builtinoptions>{ content: '保存成功', icon: 'success', size: 'sm', showCancelButton: false }) } }</builtinoptions>
2. 팝업 방법 2(이 방법은 https://에서 제공됩니다. valor-software.com/ngx-bootstrap/#/modals)
이전 방법과 동일하게 먼저 ngx-bootstrap-modal을 설치한 다음 부트스트랩 스타일 Table
1.demo 디렉터리를 가져옵니다
--- -----app.comComponent.ts
---------app.comComponent.html
---------app.module.ts
2.데모 코드
app.module. ts는 해당 모듈을 가져와서 등록합니다
//app.module.ts import { 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] }) export class AppModule { }
app.comComponent.ts
import { Component,TemplateRef } from '@angular/core'; import { BsModalService } 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<any>){//传入的是一个组件 this.modalRef = this.modalService.show(template,{class: 'modal-lg'});//在这里通过BsModalService里面的show方法把它显示出来 }; }</any>
app.comComponent.html
<p> </p><p> <button>第二种弹出方式</button> </p> <!--第二种弹出方法的组件--> <template> <p> </p> <h4 id="第二种模态框">第二种模态框</h4> <button> <span>×</span> </button> <p> </p> <p><span>第二种模态框弹出方式</span></p> <p> <button>确定</button> <button>取消</button> </p> </template>
3. 최종 효과
위의 모든 항목을 결합합니다. 모든 팝업 상자를 함께 작성하고 효과는 이렇습니다
관련 권장 사항:
BootStrap 모달 상자가 세로 중앙에 있지 않은 문제를 해결하는 방법
bootstrap 모달 상자 중첩, tabindex 속성 및 그림자 제거 방법
bootstrap3-dialog-master 모달박스 사용법에 대한 자세한 설명
위 내용은 Angular에서 모달 상자를 표시하는 두 가지 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

실제 세계에서 JavaScript의 응용 프로그램에는 서버 측 프로그래밍, 모바일 애플리케이션 개발 및 사물 인터넷 제어가 포함됩니다. 1. 서버 측 프로그래밍은 Node.js를 통해 실현되며 동시 요청 처리에 적합합니다. 2. 모바일 애플리케이션 개발은 재교육을 통해 수행되며 크로스 플랫폼 배포를 지원합니다. 3. Johnny-Five 라이브러리를 통한 IoT 장치 제어에 사용되며 하드웨어 상호 작용에 적합합니다.

일상적인 기술 도구를 사용하여 기능적 다중 테넌트 SaaS 응용 프로그램 (Edtech 앱)을 구축했으며 동일한 작업을 수행 할 수 있습니다. 먼저, 다중 테넌트 SaaS 응용 프로그램은 무엇입니까? 멀티 테넌트 SAAS 응용 프로그램은 노래에서 여러 고객에게 서비스를 제공 할 수 있습니다.

이 기사에서는 Contrim에 의해 확보 된 백엔드와의 프론트 엔드 통합을 보여 주며 Next.js를 사용하여 기능적인 Edtech SaaS 응용 프로그램을 구축합니다. Frontend는 UI 가시성을 제어하기 위해 사용자 권한을 가져오고 API가 역할 기반을 준수하도록합니다.

JavaScript는 현대 웹 개발의 핵심 언어이며 다양성과 유연성에 널리 사용됩니다. 1) 프론트 엔드 개발 : DOM 운영 및 최신 프레임 워크 (예 : React, Vue.js, Angular)를 통해 동적 웹 페이지 및 단일 페이지 응용 프로그램을 구축합니다. 2) 서버 측 개발 : Node.js는 비 차단 I/O 모델을 사용하여 높은 동시성 및 실시간 응용 프로그램을 처리합니다. 3) 모바일 및 데스크탑 애플리케이션 개발 : 크로스 플랫폼 개발은 개발 효율을 향상시키기 위해 반응 및 전자를 통해 실현됩니다.

JavaScript의 최신 트렌드에는 Typescript의 Rise, 현대 프레임 워크 및 라이브러리의 인기 및 WebAssembly의 적용이 포함됩니다. 향후 전망은보다 강력한 유형 시스템, 서버 측 JavaScript 개발, 인공 지능 및 기계 학습의 확장, IoT 및 Edge 컴퓨팅의 잠재력을 포함합니다.

JavaScript는 현대 웹 개발의 초석이며 주요 기능에는 이벤트 중심 프로그래밍, 동적 컨텐츠 생성 및 비동기 프로그래밍이 포함됩니다. 1) 이벤트 중심 프로그래밍을 사용하면 사용자 작업에 따라 웹 페이지가 동적으로 변경 될 수 있습니다. 2) 동적 컨텐츠 생성을 사용하면 조건에 따라 페이지 컨텐츠를 조정할 수 있습니다. 3) 비동기 프로그래밍은 사용자 인터페이스가 차단되지 않도록합니다. JavaScript는 웹 상호 작용, 단일 페이지 응용 프로그램 및 서버 측 개발에 널리 사용되며 사용자 경험 및 크로스 플랫폼 개발의 유연성을 크게 향상시킵니다.

Python은 데이터 과학 및 기계 학습에 더 적합한 반면 JavaScript는 프론트 엔드 및 풀 스택 개발에 더 적합합니다. 1. Python은 간결한 구문 및 풍부한 라이브러리 생태계로 유명하며 데이터 분석 및 웹 개발에 적합합니다. 2. JavaScript는 프론트 엔드 개발의 핵심입니다. Node.js는 서버 측 프로그래밍을 지원하며 풀 스택 개발에 적합합니다.

JavaScript는 이미 최신 브라우저에 내장되어 있기 때문에 설치가 필요하지 않습니다. 시작하려면 텍스트 편집기와 브라우저 만 있으면됩니다. 1) 브라우저 환경에서 태그를 통해 HTML 파일을 포함하여 실행하십시오. 2) Node.js 환경에서 Node.js를 다운로드하고 설치 한 후 명령 줄을 통해 JavaScript 파일을 실행하십시오.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Dreamweaver Mac版
시각적 웹 개발 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
