gpt4 book ai didi

javascript - ionic 2/3 ;单击时更改图像 src 标签

转载 作者:太空狗 更新时间:2023-10-29 18:06:49 26 4
gpt4 key购买 nike

我有一个 ionic 页面,其中有一个 100% 宽度和 100% 高度的图像,我想在单击它时更改图像源。

这是 html 源代码:

<ion-content>
<ion-img class="map" src="img/map.jpg" (click)="changeView()"></ion-img>
<ion-icon class="icon-bonfire" name="ios-bonfire"></ion-icon>
<ion-icon class="icon-heart" name="md-heart"></ion-icon>
<ion-icon class="icon-nuclear" name="md-nuclear"></ion-icon>
<ion-fab top right>
<button ion-fab color="whitecolor"><ion-icon class="calandaricon" name="md-calendar"></ion-icon></button>
</ion-fab>
<ion-fab top left>
<ion-searchbar> </ion-searchbar>
</ion-fab>
<ion-fab bottom right class="fablocate">
<button ion-fab color="whitecolor"><ion-icon class="locateicon" name="md-locate"></ion-icon></button>
</ion-fab>
<ion-fab (click)="ListParrots();" bottom left class="linklist">
<ion-img class="parrot-list-link" src="img/citydirty.jpg"></ion-img>
</ion-fab>
</ion-content>

ts 源码如下:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ParrotListPage } from '../parrot-list/parrot-list';

/**
* Generated class for the MapPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/

@IonicPage()
@Component({
selector: 'page-map',
templateUrl: 'map.html',
})
export class MapPage {

images: String[] = Array("img//map.jpg", "img/map1.jpg");

constructor(public navCtrl: NavController, public navParams: NavParams) {
}

changeView(){

}

ionViewDidLoad() {
console.log('ionViewDidLoad MapPage');
}

ListParrots(){
this.navCtrl.push(ParrotListPage);
}

}

有人可以帮忙完成所有的功能吗?感谢 !

最佳答案

更改模板:

<ion-img class="map" [src]="picToView" (click)="changeView()"></ion-img>

并在类中声明一个变量:

picToView:string="img/map.jpg";  // always instatiate with a valid value

和改变 View :

  changeView(){
this.picToView=.....
}

问候

汤姆

关于javascript - ionic 2/3 ;单击时更改图像 src 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46590547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com