我有,我定義的單選按鈕,一個指令,我想調用組件.. 的方法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