NgbDropdown 自动关闭 "outside" 不工作
NgbDropdown autoClose "outside" is not working
我正在使用 angular4 和 ng-bootstrap。我想在下拉菜单(文档的其余部分)外单击以关闭下拉菜单。查看文档后,我发现 autoClose 类型:布尔值 | "outside" | "inside"。
但是,当我尝试将其设置为参数 config.autoClose = 'outside' 时,我的脚本开始显示此错误“Type '"outside"' is not assignable to type 'boolean'”。“= 11=]
任何建议或帮助。
我怀疑您使用的是ng-bootstrap that doesn't have support for autoClose="outside"
yet (it was introduced very recently, in 1.0.0-beta.1
, see the changelog: https://github.com/ng-bootstrap/ng-bootstrap/blob/master/CHANGELOG.md#100-beta1-2017-08-11)
的版本
不过,经过更深入的调查,我们发现我们在 ng-bootstrap 中有一个小错误,我已经为此发送了一个 PR:https://github.com/ng-bootstrap/ng-bootstrap/pull/1754。此修复将在下一个版本之前合并。
我相信目前您可以通过像这样转换配置来使用变通方法:
(<any>config).autoClose = 'outside';
在Angular中,如果你使用的是ng-Bootstrap。如果您希望在点击屏幕的任何部分时关闭下拉菜单,请在您的代码中添加此行。
[autoClose]="true"
您的代码将如下所示
<div ngbDropdown class="d-inline-block" [autoClose]="true">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Option 1 </button>
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Option 2 </button>
</div>
如果你不想要就放。
[autoClose]="false"
我正在使用 angular4 和 ng-bootstrap。我想在下拉菜单(文档的其余部分)外单击以关闭下拉菜单。查看文档后,我发现 autoClose 类型:布尔值 | "outside" | "inside"。 但是,当我尝试将其设置为参数 config.autoClose = 'outside' 时,我的脚本开始显示此错误“Type '"outside"' is not assignable to type 'boolean'”。“= 11=]
任何建议或帮助。
我怀疑您使用的是ng-bootstrap that doesn't have support for autoClose="outside"
yet (it was introduced very recently, in 1.0.0-beta.1
, see the changelog: https://github.com/ng-bootstrap/ng-bootstrap/blob/master/CHANGELOG.md#100-beta1-2017-08-11)
不过,经过更深入的调查,我们发现我们在 ng-bootstrap 中有一个小错误,我已经为此发送了一个 PR:https://github.com/ng-bootstrap/ng-bootstrap/pull/1754。此修复将在下一个版本之前合并。
我相信目前您可以通过像这样转换配置来使用变通方法:
(<any>config).autoClose = 'outside';
在Angular中,如果你使用的是ng-Bootstrap。如果您希望在点击屏幕的任何部分时关闭下拉菜单,请在您的代码中添加此行。
[autoClose]="true"
您的代码将如下所示
<div ngbDropdown class="d-inline-block" [autoClose]="true">
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Option 1 </button>
<button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Option 2 </button>
</div>
如果你不想要就放。
[autoClose]="false"