I understand why it\'s better to use renderer instead of directly manipulating the DOM in Angular2 projects. However, I have uninstalled, clear cache, reinstalled Node, Type
You cannot inject Renderer2, but we can run RendererFactory2 to get Renderer2 instance inside @Injectable() service.
There is the way which Angular using internally in webworkers, for example.
I've solved the problem with the code below:
import { Renderer2, RendererFactory2 } from '@angular/core';
@Injectable()
class Service {
private renderer: Renderer2;
constructor(rendererFactory: RendererFactory2) {
this.renderer = rendererFactory.createRenderer(null, null);
}
}
Parameters of RendererFactory2.createRenderer method are:
hostElement with type anytype with type RendererType2|nullYou can see that (null, null) parameters are here:
https://github.com/angular/angular/blob/e3140ae888ac4037a5f119efaec7b1eaf8726286/packages/core/src/render/api.ts#L129