hisairnessag3
hisairnessag3

Reputation: 276

Error from angular migration, 2.1.x => 4.1.3

I am working on updating quite a hefty project, that is way past due on its update schedule.

I am getting an error related to browserdomadapter:

Property 'query' does not exist on type 'BrowserDomAdapter'.

Here is the code:

constructor(titleService: Title) {

  this.titleService = titleService;

  this.dom = new BrowserDomAdapter();

  this.headElement = this.dom.query('head');
  this.metaDescription = this.getOrCreateMetaElement('description');
  this.robots = this.getOrCreateMetaElement('robots');
}

and:

private getOrCreateMetaElement(name: string): HTMLElement {
    let el: HTMLElement; 
    el = this.dom.query('meta[name=' + name + ']'); 
    if (el === null) {
        el = this.dom.createElement('meta'); 
        el.setAttribute('name', name);
        this.headElement.appendChild(el);
    }
    return el;
}   

I also had to migrate from webpack 1.x.x to the latest as well.

Upvotes: 1

Views: 59

Answers (1)

Z. Bagley
Z. Bagley

Reputation: 9260

BrowsDomAdapter is no longer supported. The new method is to inject DOCUMENT.

import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';

@Component({})
export class MyClass {

    constructor (@Inject(DOCUMENT) private document) { }

    doSomething() {
        this.document.someMethodOfDocument();
    }
}

Upvotes: 2

Related Questions