Angular 5 - 使用(单击)而不是 <a href="#target"></a>
Angular 5 - Using (click) instead of <a href="#target"></a>
我有一个 link 可以打开模式对话框:
<a href="#openModal">Open Modal</a>
但我想使用 angular (点击) 或类似的方式来打开模式。
我该怎么做?
看看 ng-bootstrap,它是一个非常强大的工具,可以将预构建的用户界面组件添加到您的应用程序中,我以前用过这个工具并且效果很好。设置可能有点混乱,但他们的文档很有帮助。
做这样的事情:
<button (click)="openModal()">Open Modal</button>
在打开模态中:
openModal() {
window.location.href = 'yoururl';
}
也许这就是您要找的,
您可以在组件中引用 window 对象:
private window: any = window;
然后在您的模板中使用:
<button (click)="window.location.href = '#openModal'">Open Modal</button>
但请记住描述here
Referencing global browser objects like document or window directly from within your code is possible, but not encouraged and considered bad practice.
并且建议您注册 WindowRef
作为提供商。
我有一个 link 可以打开模式对话框:
<a href="#openModal">Open Modal</a>
但我想使用 angular (点击) 或类似的方式来打开模式。
我该怎么做?
看看 ng-bootstrap,它是一个非常强大的工具,可以将预构建的用户界面组件添加到您的应用程序中,我以前用过这个工具并且效果很好。设置可能有点混乱,但他们的文档很有帮助。
做这样的事情:
<button (click)="openModal()">Open Modal</button>
在打开模态中:
openModal() {
window.location.href = 'yoururl';
}
也许这就是您要找的, 您可以在组件中引用 window 对象:
private window: any = window;
然后在您的模板中使用:
<button (click)="window.location.href = '#openModal'">Open Modal</button>
但请记住描述here
Referencing global browser objects like document or window directly from within your code is possible, but not encouraged and considered bad practice.
并且建议您注册 WindowRef
作为提供商。