简体   繁体   中英

AngularJS Show/Hide images

I have a list with a name + url_image:

{
    "_id": ObjectId("54324ef2dbf522b45166a746"),
    "name": "imageOCR1",
    "url_image": "http://meta-e.aib.uni-linz.ac.at/ocr/images/biographie_oc
    r.gif ",
    "__v": 0
} {
    "_id": ObjectId("54324ef2dbf522b45166a747"),
    "name": "imageOCR2",
    "url_image": "http://www.textcreationpartnership.org/files/2012/02/ocr.
    jpg ",
    "__v": 0
}

So I can easly display the names:

<div class="container" ng-controller="imageController">
    <div ng-repeat="product in products">
        <h3>name: {{product.name}}</h3>
    </div>
</div>

but It doesn't work if I want to click the name and display the image. Then I want to click on the other name, hide the previous image and diplay the new image.

<a onClick="showImage();" style="cursor: pointer; cursor: hand;">{{product.name}}</a>
<img id="loadingImage" src="{{product.url_image}}" style="visibility:hidden" height="650" width="600" /> 

My function showImage()

function showImage() {
    document.getElementById('loadingImage').style.visibility = "visible";
}

Thanks for your help!

Carlos

Try this piece of code:

<div class="container" ng-controller="imageController">
  <div ng-repeat="product in products">
    <h3 ng-click="products.chosen=product">name: {{product.name}}</h3>
    <img ng-if="products.chosen==product" ng-src="{{product.url_image}}"/>
  </div>
</div>

You can use ng-click function {{product.name}}

and add ng-show

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM