'No provider for child component's imports

I'm testing a component which has a child component. I keep getting errors about NullInjectorError: No provider for Camera, then I add Camera to providers then I get an error NullInjectorError: No provider for File and so on.

Is there a way to handle all the child component's imports or do I need to just import these items for every child and sibling of the component I'm testing?

Parent.Page

import { ChildComponent } from 'src/app/components/child/child.component';

@Component({
  selector: 'app-parent',
  templateUrl: './parent.page.html',
  styleUrls: ['./parent.page.scss'],
})
export class ParentPage implements OnInit, OnDestroy {
  // prettier-ignore
  @ViewChild(ChildComponent) child: ChildComponent;

  constructor(
    private logger: NGXLogger,
  ) {}
  ...
}

Child.Component

import { Camera } from '@awesome-cordova-plugins/camera/ngx';
import { File, Entry } from '@awesome-cordova-plugins/file/ngx';

@Component({
  selector: 'app-child',
  templateUrl: './child.component.html',
  styleUrls: ['./child.component.scss'],
})
export class ChildComponent implements OnInit {

  constructor(
    private camera: Camera,
    private file: File,
  ) {}

  ngOnInit() {
    ...
  }
}

In Parent's spec file I have added ChildComponent to the declarations



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source