我不会自定义引导程序下拉组件。 我使用angular 7,因此可以通过ng-bootstrap库访问boostrap功能。
我要修复ng-bootstrap下拉列表中的问题。 它将样式属性设置在标记的正确位置(左属性),我不想要那样。
所以我正在尝试扩展NgbDropdownMenu并覆盖方法:
position(triggerEl: any, placement: any)
当前的问题是将ngbDropdown注入我的子类中。
Origin NgbDropdownMenu的注入部分很奇怪:
NgbDropdownMenuDirective.ctorParameters = () => [
{ type: undefined, decorators: [{ type: Inject, args: [forwardRef(() => NgbDropdown),] }] },
{ type: ElementRef },
{ type: Renderer2 }
];
由于类型系统限制,我无法在ts文件中复制以上代码段。
如果我删除了代码段,则网页会出现异常,提示未找到NgbDropdown,但该位置在那里。一切都可以与NgbDropdownMenu一起使用。
import {
ElementRef,
forwardRef,
Directive, Input, TemplateRef,
EventEmitter,
Renderer2,
Injector, Inject
} from "@angular/core";
import { NgbDropdown, NgbDropdownMenu } from '@ng-bootstrap/ng-bootstrap/esm2015/dropdown/dropdown' ;
@Directive({
selector: '[appCustomDropdown]',
exportAs:'appCustomDropdown'
})
export class CustomDropdownDirective extends NgbDropdownMenu {
constructor(dropdown: any, _elementRef: ElementRef<HTMLElement>, _renderer: Renderer2) {
super(dropdown, _elementRef, _renderer);
}
position(triggerEl: any, placement: any): void {
}
}
尝试用js文件和ctorParameters而不是ts导致相同结果。 NbdDropdown依赖关系无法解决
core.js:14597 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[CustomDropdownDirective -> NgbDropdown]:
StaticInjectorError(Platform: core)[CustomDropdownDirective -> NgbDropdown]:
NullInjectorError: No provider for NgbDropdown!
Error: StaticInjectorError(AppModule)[CustomDropdownDirective -> NgbDropdown]:
StaticInjectorError(Platform: core)[CustomDropdownDirective -> NgbDropdown]:
NullInjectorError: No provider for NgbDropdown!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:3228)
at resolveToken (core.js:3473)
at tryResolveToken (core.js:3417)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:3314)
at resolveToken (core.js:3473)
at tryResolveToken (core.js:3417)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:3314)
at resolveNgModuleDep (core.js:19784)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:20473)
at resolveNgModuleDep (core.js:19784)
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:3228)
at resolveToken (core.js:3473)
at tryResolveToken (core.js:3417)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:3314)
at resolveToken (core.js:3473)
at tryResolveToken (core.js:3417)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:3314)
at resolveNgModuleDep (core.js:19784)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:20473)
at resolveNgModuleDep (core.js:19784)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:16147)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
defaultErrorLogger @ core.js:14597
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:14645
next @ core.js:16628
schedulerFn @ core.js:12609
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:196
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:134
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:77
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:12593
(anonymous) @ core.js:16178
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138
push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:16115
onHandleError @ core.js:16178
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:392
push../node_modules/zone.js/dist/zone.js.Zone.runGuarded @ zone.js:154
_loop_1 @ zone.js:677
api.microtaskDrainDone @ zone.js:686
drainMicroTaskQueue @ zone.js:602
Promise.then (async)
scheduleMicroTask @ zone.js:578
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:410
onScheduleTask @ zone.js:297
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:401
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:232
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:252
scheduleResolveOrReject @ zone.js:862
resolvePromise @ zone.js:808
(anonymous) @ zone.js:724
webpackJsonpCallback @ bootstrap:25
(anonymous) @ main-frame-main-frame-module.js:1