【发布时间】:2017-07-24 02:35:07
【问题描述】:
我有一个图像元素,我正在尝试将ViewChild 用于:
<img class="postimage" #imagey [src]="">
我的控制器是这样的:
import { Component, ViewChild, ElementRef, Renderer } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
/**
* Generated class for the PostpagePage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-postpage',
templateUrl: 'postpage.html',
})
export class PostpagePage {
@ViewChild('imagey') image:ElementRef;
imageHolder;
constructor(public myrenderer: Renderer, public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
this.imageHolder = this.navParams.get("path");
this.myrenderer.setElementAttribute(this.image.nativeElement, 'src', this.imageHolder);
console.log(JSON.stringify(this.image));
}
pushPage(){
// push another page on to the navigation stack
// causing the nav controller to transition to the new page
// optional data can also be passed to the pushed page.
//this.navCtrl.push(SignUpPage);
}
}
ionViewDidLoad 中控制台消息的结果是:
{"nativeElement":{}}
它似乎没有返回一个元素。
【问题讨论】:
标签: html image angular ionic-framework element