Angular2:模态对话框不捕获键事件(Angular2: Modal Dialog does not catch key-events)
我正在按照模式对话框的解决方案和下面的评论。 因为它们太多了所以为了清晰起见我决定制作一个新的q我有适应的版本:
import { Component, ViewChild } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; @Component({ selector: 'app-modal', template: ` <div #myModal class="modal fade" tabindex="-1" [ngClass]="{'in': visibleAnimate}" [ngStyle]="{'display': visible ? 'block' : 'none', 'opacity': visibleAnimate ? 1 : 0}"> <div class="modal-dialog"> <div class="modal-content" (click)="$event.stopPropagation();"> <div class="modal-header"> <ng-content select=".app-modal-header"></ng-content> </div> <div class="modal-body"> <ng-content select=".app-modal-body"></ng-content> </div> <div class="modal-footer"> <ng-content select=".app-modal-footer"></ng-content> </div> </div> </div> </div> ` }) export class ModalComponent { @ViewChild('myModal') public myModal: ModalDirective; public visible = false; private visibleAnimate = false; public show(): void { this.visible = true; setTimeout(() => this.visibleAnimate = true); document.body.className += ' modal-open'; } public hide(): void { this.visibleAnimate = false; document.body.className = document.body.className.replace('modal-open', ''); setTimeout(() => this.visible = false, 300); } public onContainerClicked(event: MouseEvent): void { if ((<HTMLElement>event.target).classList.contains('modal')) { this.hide(); } } }
我现在使用这种方法的主要问题是:
- 键盘事件不会在模态对话框中捕获,而是发送到后向。 怎么预防这个?
- 正如评论部分所述:如何多次叠加对话框? 即,有一个模态对话框,例如编辑,而不是顶部的附加作为错误通知。 这出现在后台......
编辑:检查几个来源后,我想出了以下内容:
我需要安装
ngx-bootstrap
,在app.module.ts
添加import { ModalModule } from 'ngx-bootstrap'; ... @NgModule({ imports: [ ... ModalModule ],
并添加
systemjs.config.js
// ngx-bootstrap 'ngx-bootstrap' : { format : 'cjs', main : 'bundles/ngx-bootstrap.umd.js', defaultExtension : 'js' }, 'moment' : { main : 'moment.js', defaultExtension : 'js' },
通过上面的更改(以及udpated代码),我仍然有问题在第一个模式前面获得第二个模态对话框。 提示?
I'm following the solution for a modal dialog and the comments from below. Since they are so many I decided to make a new q for the sake of clarity I have the adapted version:
import { Component, ViewChild } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; @Component({ selector: 'app-modal', template: ` <div #myModal class="modal fade" tabindex="-1" [ngClass]="{'in': visibleAnimate}" [ngStyle]="{'display': visible ? 'block' : 'none', 'opacity': visibleAnimate ? 1 : 0}"> <div class="modal-dialog"> <div class="modal-content" (click)="$event.stopPropagation();"> <div class="modal-header"> <ng-content select=".app-modal-header"></ng-content> </div> <div class="modal-body"> <ng-content select=".app-modal-body"></ng-content> </div> <div class="modal-footer"> <ng-content select=".app-modal-footer"></ng-content> </div> </div> </div> </div> ` }) export class ModalComponent { @ViewChild('myModal') public myModal: ModalDirective; public visible = false; private visibleAnimate = false; public show(): void { this.visible = true; setTimeout(() => this.visibleAnimate = true); document.body.className += ' modal-open'; } public hide(): void { this.visibleAnimate = false; document.body.className = document.body.className.replace('modal-open', ''); setTimeout(() => this.visible = false, 300); } public onContainerClicked(event: MouseEvent): void { if ((<HTMLElement>event.target).classList.contains('modal')) { this.hide(); } } }
The main problem I have now with this approach are:
- Keyboard-events are not caught in the modal dialog but rather sent to the backward. How to prevent this?
- As asked in the comment section: How to overlay the dialog multiple times? i.e. to have a modal dialog for e.g. editing and than an additional on the top as Error-notification. This appears in the background...
EDIT: After checking several sources I figured out the following:
I need to install
ngx-bootstrap
, add in theapp.module.ts
import { ModalModule } from 'ngx-bootstrap'; ... @NgModule({ imports: [ ... ModalModule ],
and add in the
systemjs.config.js
// ngx-bootstrap 'ngx-bootstrap' : { format : 'cjs', main : 'bundles/ngx-bootstrap.umd.js', defaultExtension : 'js' }, 'moment' : { main : 'moment.js', defaultExtension : 'js' },
With the above changes (and the udpated code) I still have problems to get a second modal dialog in front of the first one. Hints?
原文:https://stackoverflow.com/questions/43390799
最满意答案
我不确定你的意思。 在C和C ++中,函数必须在调用之前声明,否则编译器将不知道如何验证参数和返回值。
I'm not sure what you mean by this. In C and C++, a function must be declared before it is called, otherwise the compiler won't know how to verify your arguments and return values.
相关问答
更多-
根据Revel文档,系统通过扫描源目录以查找匿名嵌入*Revel.Controller任何内容,在调试模式下查找控制器。 您看到的错误是由于Revel在此控制器扫描初始化期间进行动态反射和拧紧。 所以现在问题是:为什么扫描控制器时遇到问题? 您的代码似乎试图在EventStream中扩展控制器,Revel调试控制器发现代码将尝试将其作为Controller读取。 但是,目前的代码目前通过嵌入*GormController而不是GormController违反了框架的期望。 请参阅Controllers文档的 ...
-
调用方面声明的方法(Calling methods declared in an aspect)[2022-02-05]
我找到了一种方法 - 显然,aspectJ不仅可以定义额外的字段,还可以定义方法。 为此,我们只需要修改下面的方面(注意我如何用Point.替换static Point. ) aspect PointObserving { private Vector Point.observers = new Vector(); public void Point.addObserver(Point p, Screen s) { observers.add(s); //Legal to ... -
我不确定你的意思。 在C和C ++中,函数必须在调用之前声明,否则编译器将不知道如何验证参数和返回值。 I'm not sure what you mean by this. In C and C++, a function must be declared before it is called, otherwise the compiler won't know how to verify your arguments and return values.
-
从另一个文件调用函数,其中包含在主文件中声明的变量(Calling function from another file, which contains variable declared in main file)[2023-08-30]
cut正试图使用另一个文件中的全局变量。 即使你找到了解决循环导入的方法,但是对于事情来说这是一个混乱的方式。 编写独立于全局变量运行的函数会更好。 首先,它使修改和测试更容易。 当你需要处理分配command=function和function需要变量时, functools.partial是你的朋友。 def cut(tk_text_obj): tk_text_obj.event_generate('<>') return 'break' 然后在主文件中,首先声明main_t ... -
为什么这个函数声明两次?(Why is this function declared twice? Where is the callback function declared?)[2021-09-02]
JavaScript首先编译所有函数名称的列表,然后运行,因此calculateVelocity已经定义。 另外,你是正确的, (velX, velY) => {}是回调函数,并且正在调用该函数。 它采用新的Arrow功能格式。 以下两者是相同的: this.calculateVelocity(x, y, (velX, velY) => { ... }); this.calculateVelocity(x, y, function(velX, velY) { ... }); 在setPo ... -
C将从上到下解析您的文件。 在验证函数的使用之前,它至少需要了解函数的签名。 这就是您遇到问题的原因。 如果你想在定义之前告诉C一个函数,你需要对函数进行原型设计。 这实质上是将函数的签名添加到文件中以供C处理。 例如,您可以使用以下内容对test1进行原型设计 void test1(); 然后你可以在它定义之前调用它 void test1(); void test() { test1(); } void test1() {} C will parse your file from top to bot ...
-
你班级的定义: class Foo { public: void a() { b(); } void b() { } }; 具有相同的含义: class Foo { public: void a(); void b(); }; void Foo::a() { b(); } void Foo::b() { } 这就是函数体看到所有成员的原因,就好像该类已经完全定义一样。 这是通过C ++标准中规定的方式: 3.3.7 / 1在类中声明的名称的潜在范围不仅包括名称声明点后 ...
-
从迭代器调用函数(Calling functions from an iterator)[2021-03-05]
if(**itr.getPosition().y == i) 需要改为 if((*itr)->getPosition().y == i) // preferred 要么 if((**itr).getPosition().y == i) // eh, ok if(**itr.getPosition().y == i) Needs to be changed to if((*itr)->getPosition().y == i) // preferred Or if((**itr).getPositi ... -
我不认为可以做到。 在Info.Func[]调用中的符号查找不会将名称解析为单位范围和标识符,而是对名为“Test.ClickProc”的符号进行简单查找。 但是,由于ClickProc过程符号名为“ClickProc”,因此查找无法找到它。 我想也许可以通过符号表手动找到程序符号...... var FExecution: IdwsProgramExecution; UnitSymbol: TUnitMainSymbol; FuncSymbol: TFuncSymbol; Info: II ...
-
允许返回指向具有静态存储的对象的指针,例如 #include
int *foo(void) { static int x; printf("%d\n", x); return &x; } int main(void) { int *p = foo(); *p = 10; foo(); return 0; } 将打印: 0 10 或者,您当然可以将指针传递给指针并将其存储在那里而不是返回它。 It's allowed to r ...