How can I inject Document in service?

Discussão em 'Angular' iniciado por RJo, Junho 19, 2025.

  1. RJo

    RJo Guest

    I have an Angular 2 application. For mocking the Document object in tests, I'd like to inject it to the service like:

    import { Document } from '??'

    @Injectable()
    export class MyService {
    constructor(document: Document) {}
    }


    The Title service of Angular uses the internal getDOM() method.

    Is there any simple way to inject the Document to the service? Also, how should I reference it in the providers array?

    Continue reading...

Compartilhe esta Página