Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Cannot set property 'innerHTML' of null

Estou com problema no exercício do tópico "Apresentando o modelo para o usuário" do curso TypeScript 1 e não consigo solucionar. Podem me ajudar por favor.

Após executar os comandos ;view = new NegociacoesView('#negociacoesView'); view.update();

recebo o erro; Cannot set property 'innerHTML' of null at NegociacoesView.update (NegociacoesView.js:7) at :1:6

Seguem minhas classes: class NegociacoesView { private _elemento: Element;

constructor(seletor: string) {
    this._elemento = document.querySelector(seletor);
}

update(): void {
    this._elemento.innerHTML = this.template();
}

template(): string {
    return `
    <table class="table table-hover table-bordered">
        <thead>
            <tr>
                <th>DATA</th>
                <th>QUANTIDADE</th>
                <th>VALOR</th>
                <th>VOLUME</th>
            </tr>
        </thead>

        <tbody>
        </tbody>

        <tfoot>
        </tfoot>
    </table>               
    `
}

}

class NegociacaoController {

private _inputData: HTMLInputElement;
private _inputQuantidade: HTMLInputElement;
private _inputValor: HTMLInputElement;
private _negociacoes = new Negociacoes();
private _negociacoesView = new NegociacoesView('#negociacoesView');

constructor() {
    this._inputData = <HTMLInputElement>document.querySelector('#data');
    this._inputQuantidade = <HTMLInputElement>document.querySelector('#quantidade');
    this._inputValor = <HTMLInputElement>document.querySelector('#valor');
}

adiciona(event: Event) {
    event.preventDefault();

    const negociacao = new Negociacao(
        new Date(this._inputData.value.replace(/-/g, ',')), 
        parseInt(this._inputQuantidade.value),
        parseFloat(this._inputValor.value)
    );

}

}

2 respostas
solução!

O elemento html com o id "negociacoesView" existe?

Bom dia, problema resilvido.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software