1

I encountered a little problem. I am making a little gallery and saw html like this:

<div class="thumbnails">
    <img onmouseover="preview.src=img1.src" name="img1" src="images/img1.jpg" alt=""/>
    <img onmouseover="preview.src=img2.src" name="img2" src="images/img2.jpg" alt=""/>
    <img onmouseover="preview.src=img3.src" name="img3" src="images/img3.jpg" alt=""/>
    <img onmouseover="preview.src=img4.src" name="img4" src="images/img4.jpg" alt=""/>
    <img onmouseover="preview.src=img5.src" name="img5" src="images/img5.jpg" alt=""/>
</div><br/>

<div class="preview" align="center">
    <img name="preview" src="images/img1.jpg" alt=""/>
</div>

And now I wanted to do it repeatedly from json object So I did sth like this:

    <div class="mythumbnails">
        <img ng-click="mypreview.src=img{{$index}}.src" src="data:image/png;base64,{{x}}" name="img{{$index}}" ng-repeat="x in data.gallery" alt=""/>
    </div><br/>


    <div class="mypreview" align="center">
        <img name="mypreview" src="data:image/png;base64,{{ data.gallery[0] }}" alt=""/>
    </div>

Firstly I did mouseover but I couldn't use {{ $index }}, so I did ng-mouseover and ng-click. I don't know if the expression is wrong or what.

Thanks up front :)

@edit The problem is when I click the main picture from mypreview doesn't change.

@edit2 In Firebug:

<img class="ng-scope" ng-click="mypreview.src=img4.src" src="data:image/png;base64,..." name="img4" ng-repeat="x in data.gallery" alt="">

So it the index works.

@edit3 At the beginning I got error in console: Error: [$parse:syntax] http://errors.angularjs.org/1.4.8/$parse/syntax?p0=%7B&p1=is%20an%20unexpected%20token&p2=18&p3=mypreview.src%3Dimg%7B%7B%24index%7D%7D.src&p4=%7B%7B%24index%7D%7D.src

0

2 Answers 2

3

Try to replace

src="data:image/png;base64,{{ data.gallery[0] }}"

to

data-ng-src="data:image/png;base64,{{ data.gallery[0] }}"
Sign up to request clarification or add additional context in comments.

5 Comments

Hate this enter system Ok, lets go deeper. mypreview.src=img{{$index}}.src this will be evaluated on this: mypreview.src=img1.src . Is it ok for your data?
Yes, yes. I saw in firebug that it is ok - <img class="ng-scope" ng-click="mypreview.src=img4.src" src="data:image/png;base64,..." name="img4" ng-repeat="x in data.gallery" alt="">
Please, can you make one stupid thing... Replace ALL your src to ng-src... And check console for errors...
rror: [$parse:syntax] errors.angularjs.org/1.4.8/$parse/… ... <img ng-click="mypreview.src=img{{$index}}.src" ng-src="data:image/png;base64,{{x}}" name="img{{$index}}" ng-repeat="x in data.gallery" alt="">
So first we need to do is to drop this error off. Try to replace plain ng-click function invocation to invocation from scope. Smth like this ng-click=getPreview($index) $scope.getPreview = function(index) { $scope.mypreview.src = "img"+index+".src"; }
0

If anyone would be interested I did this:

onmouseover="mypreview.src=this.src"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.