我有,我定义的单选按钮,一个指令,我想调用组件.. 的方法Whene我注入的构造函数,我得到这个错误的组件:ERROR Error: No provider for FoldersComponent!
错误:没有提供程序组件
directive.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 {
}
}
folder.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");
}
}
folder.compo nent.html
<input type="radio" icheck name="filters.type" [(ngModel)]="filters.type" value="IN"> (IN)
我@NgModule
@NgModule({
declarations: [
AppComponent,
LoginComponent,
FoldersComponent,
],
它应该工作https://plnkr.co /编辑/ ecPrqOp4nDIG71vo4ksT?p =预览 – yurzui
很酷... thx ..;我不明白在我的代码当我删除我的构造函数'私人parentCmp:FoldersComponent'的参数,它是工作,但是当我添加它使用组件的方法我得到错误..非常有趣.. – user1814879
Thxxx这么多它是工作 – user1814879