I have a directive where I defined a radio button and I want to call a method of a component ..
Whene I inject the component in constructor I got this error : 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.component.html
<input type="radio" icheck name="filters.type" [(ngModel)]="filters.type"                   value="IN"> (IN)
My @NgModule
@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    FoldersComponent,
  ],
It seems you have missed to register FoldersComponent  to @NgModule({})
Can you post your main file where you have used NgModule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With