【问题标题】:HAML : Img tag inside anchor tagHAML:锚标签内的 Img 标签
【发布时间】:2013-07-26 22:02:39
【问题描述】:

这是一个付出了很多努力的人:

 .picture{:"ng-repeat" => "picture in pictures"}

      %h2 {{picture.title}}

      %a{ :ng-href => "pictures/{{$index}}"}
      %img{:src => "{{picture.url}}"

尝试过

%a{ :ng-href => "pictures/{{$index}}"}
      %img{:src => "{{picture.url}}"

%a{ :ng-href => "pictures/{{$index}}"}< %img{:src => "{{picture.url}}">

但没有任何效果。在 haml 文档中找不到我的问题的答案(这些文档太糟糕了......)。有谁知道怎么放进haml里面?

【问题讨论】:

  • 你能试着更好地解释你的问题吗?我不确定你在问什么。
  • img 不在 %a 标签内。
  • 结果如何?您的图像放在 atag 之后?
  • 视情况而定。在第一段代码之后。在第二个它的错误和第三个也有错误(在编译期间,我使用 .hamlc 格式(rails + angular)
  • 我的错误是我在新行中使用了制表符而不是空格。大声笑

标签: html angularjs anchor haml


【解决方案1】:

我在将图像正确放置在锚点内时遇到了同样的问题,并得到了以下轨道解决方案:

在您的 view.html.haml 中,嵌入了 rails 助手:

= link_to image_tag('name_of_the_asset', alt: 'title'), root_path

root_path 正在使用 url_for 助手,但可以更改为“https://www.someexample.com”)

【讨论】: