收到错误:'BsDropdownDirective'既不'ComponentType'也不'DirectiveType'



我在我的HTML中使用Angular 9和NgX bootstrap@6.2.0,我有如下所示:-

<div class="btn-group" dropdown>
<button id="button-basic" dropdownToggle type="button" class="btn btn-primary dropdown-toggle"
aria-controls="dropdown-basic">
Button dropdown <span class="caret"></span>
</button>
<ul id="dropdown-basic" *dropdownMenu class="dropdown-menu"
role="menu" aria-labelledby="button-basic">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
</div>

在我的ts文件中,我有这样的

import { Component } from '@angular/core';

@Component({
selector: 'demo-dropdown-basic',
templateUrl: './basic.html',
providers: [
{
provide: BsDropdownConfig,
useValue: { isAnimated: true, autoClose: true },
},
],
})
export class DemoDropdownBasicComponent {}

当我运行代码时,我得到以下错误:-

core.js:6241 ERROR Error: 'BsDropdownDirective' is neither 'ComponentType' or 'DirectiveType'.
at extractDirectiveDef (core.js:1964)
at Array.map (<anonymous>)
at def.directiveDefs (core.js:1926)
at createTView (core.js:12307)
at getOrCreateTComponentView (core.js:12252)
at addComponentLogic (core.js:13224)
at instantiateAllDirectives (core.js:12994)
at createDirectivesInstances (core.js:12209)
at ɵɵelementStart (core.js:21302)

你需要定义BsDropdownConfig

import { Component } from '@angular/core';
import { BsDropdownConfig } from 'ngx-bootstrap/dropdown'; // add this line
@Component({
selector: 'demo-dropdown-basic',
templateUrl: './basic.html',
providers: [{ provide: BsDropdownConfig, useValue: { isAnimated: true, autoClose: true } }]
})
export class DemoDropdownBasicComponent {}

相关内容

  • 没有找到相关文章

最新更新