0

I'm trying to show the image from the database. However, I can't put the angular variable inside the @ sign of the Scala template.

<div class="col-sm-6 col-md-3" ng-repeat="product in products">
    <a href="#">
        <div class="thumbnail">
            <img class="img-responsive" ng-src="@routes.BookStore.getImage(product.name)">
            ...
        </div>
    </a>
</div>

It gave Error: Can't find the product variable. I also tried:

 <img class="img-responsive" ng-src="@routes.BookStore.getImage( {{ product.name }} )">

It still gave me the same error. How can I use the AngularJs variable inside the Scala template?

lvarayut
  • 13,963
  • 17
  • 63
  • 87

1 Answers1

0

You CAN NOT that's obvious - Scala template is processed at backend side much, much earlier then it arrives to frontend. Instead your Angular app should have some method which will create a string containing path to the image literally, something like /book-store/get-image/foo.jpg and then add a route to your routes file:

GET /book-store/get-image/:fileName   controllers.BookStore.getImage(fileName)

Optionally you can try to go with javascriptRoutes, but it's not necessary.

Community
  • 1
  • 1
biesior
  • 55,576
  • 10
  • 125
  • 182
  • I did the same thing as you mentioned. I have the route as same as your answer and I also have the `product.name` contained `foo.jpg`. So, how can I call my route by passing the file name variable? – lvarayut Jun 02 '14 at 14:10
  • As I started my answer _You CAN NOT_ use URL's generated by Angular instead – biesior Jun 02 '14 at 14:20