【发布时间】:2018-08-23 10:57:45
【问题描述】:
当单击关闭模式按钮以及在模式外单击鼠标时,模式会关闭 我想调用与单击关闭模态按钮时调用的相同函数,以及单击模态外部时调用的函数。我不确定如何在 Angular 2 中执行此操作。请您分享您的想法。 此外,我的 Modal 是我的主要 html 的一部分,它没有单独的组件或 html ...... 谢谢
import { Component, OnInit, NgModule, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core';
import * as jQuery from 'jquery';
export class Component implements OnInit {
@ViewChild('newModal') newModal: ElementRef;
public OpenModal(){
jQuery(this.newModal.nativeElement).modal('show');
}
public CloseModal(){
Includes actions taken when close modal button is clicked - I want the same function to be called with I click outside the model
}
}
我在 html 中尝试了以下内容,但每当我单击组件上的任何位置而不是模式区域时,它就会运行。
(clickOutside)="CloseModal()";
【问题讨论】:
-
你用什么来创建模态,引导程序?一些角度库?您需要挂钩任何发生的事件并调用相同的代码。
-
嗨,Jason,我已经更新了我的问题并提供了更多详细信息,请查看并分享您的意见
标签: angular angular2-template angular2-forms angular2-directives