最近使用Ng-Zorro, Button + nz-dropdown-menu 组合出现了一个奇怪的问题。按照官网文档运行有以下异常。
编译提示如下:
Can't bind to 'nzDropdownMenu' since it isn't a known property of 'button'.
'nz-dropdown-menu' is not a known element:
1. If 'nz-dropdown-menu' is an Angular component, then verify that it is part of this module.
2. If 'nz-dropdown-menu' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
或者运行提示如下:
Error: Template parse errors:
There is no directive with "exportAs" set to "exportDropdownMenu" (" nzType="down"></i></button>
<nz-dropdown-menu [ERROR ->]#dropdownMenu="exportDropdownMenu">
<ul nz-menu>
"): ng:///EquipmentModule/EquipmentComponent.html@17:42
网上有很多解决办法,包括 import FormsModule 等,但是都没解决我遇到的情况。后来在Ng Zorro文档的另外一个地方找到了原因。需要引用NzDropDownModule
然后就好了。
效果如下: