gpt4 book ai didi

angular - 错误 : No providers for Component

转载 作者:行者123 更新时间:2023-12-03 20:32:05 25 4
gpt4 key购买 nike

我有一个指令,我在其中定义了一个单选按钮,我想调用一个组件的方法..
当我在构造函数中注入(inject)组件时,出现此错误:ERROR Error: No provider for FoldersComponent!

指令.ts

   import { FoldersComponent } from '../folders/folders.component';
import { Directive, ElementRef, HostListener, Input, AfterViewInit, ViewChild, EventEmitter, Output } from '@angular/core';

declare var jQuery: any;

@Directive({
selector: '[icheck]'
})

export class IcheckDirective implements AfterViewInit {

@Output('icheck')
callComponentFunction: EventEmitter<any> = new EventEmitter<any>();
constructor(private el: ElementRef, private parentCmp: FoldersComponent) {
jQuery(this.el.nativeElement).iCheck({
checkboxClass: 'icheckbox_square-aero',
radioClass: 'iradio_square-aero'
}).on('ifChecked', function(event) {
if (jQuery('input').attr('type') === 'radio') {
this.parentCmp.selectType();
}
});
}

ngAfterViewInit(): void {
}
}

文件夹.component.ts
@Component({
selector: 'app-folders',
templateUrl: './folders.component.html',
styleUrls: ['./folders.component.css'],
})
export class FoldersComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private router: Router
) { }

selectType() {
// alert();
console.log("Ici");
}
}

文件夹.component.html
<input type="radio" icheck name="filters.type" [(ngModel)]="filters.type"                   value="IN"> (IN)

我的@NgModule
@NgModule({
declarations: [
AppComponent,
LoginComponent,
FoldersComponent,
],

最佳答案

看来你错过了注册FoldersComponent@NgModule({})
你能把你的主文件贴在你用过的地方吗NgModule

关于angular - 错误 : No providers for Component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44541613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com