I want to get the "src" of an html image but it shows this error. I'm trying to do it as follows
import { NavController, NavParams } from 'ionic-angular';
import { Component } from '@angular/core';
@Component({
selector: 'page-sombraFase1',
templateUrl: 'sombraFase1.html',
})
export class SombraFase1Page {
src: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
var srcuu:any = (<HTMLImageElement>document.getElementById("sol")).src;
}
ionViewDidEnter(){
console.log(this.src);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><ion-header></ion-header><ion-contentclass="bgcSombra" padding>
<img src="assets/img/cabecalho.png" alt="Cabeçalho" id="cabecalho" (click)="voltarHome()">
<div class="divDica">
<img src="assets/img/audio.png" class="dica">
<img src="assets/img/msgDica.png" class="msgDica">
</div>
<div class="imgsGame">
<img src="assets/img/Sol.png" id="sol">
<img src="assets/img/lua.png" id="lua">
<img src="assets/img/Sol-sombra.png" id="solSombra">
<img src="assets/img/lua-sombra.png" id="luaSombra">
</div>
</ion-content>
It returns null, how can I resolve this problem?