我有一个指令,我在其中定义了一个单选按钮,我想调用一个组件的方法..
当我在构造函数中注入(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/