angular - 错误 : No providers for Component

标签 angular angular2-directives

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

相关文章:

angular - 多个 ngx 分页错误 Angular 2

javascript - 使用 Pixi.js v4 和 Typerscript (IONIC 2) 绘制圆形

angular - 从 Angular 4 中的 API 获取数据

angular - 我如何知道子元素何时在 Angular 中完成渲染?

javascript - Angular 2 属性绑定(bind)生命周期

angular - 如何检查是否在组件上触发了变更检测

angular - 单击时隐藏在元素 Angular 4 之外

javascript - 组件的 Angular 2 导入在 VS 中有效,但在浏览器中给出 404

angular - 防止 fontawesome 的 svg 翻译

javascript - Angular 2 模块.id