【问题标题】:Handling assets on angularjs and middleman在 angularjs 和中间人上处理资产
【发布时间】:2014-09-25 19:15:51
【问题描述】:

我很难将 angularjs 集成到我的中间人应用程序中。我正在关注 angularjs 的 phonecatApp 教程以及关于模板和链接图像的教程 6。输出很好,但控制台上显示了一个烦人的错误。

GET http://localhost:4567/images/ 404 (Not Found)

现在我读到,当将 angulars 表达式直接放入图像元素的 src 属性时会出现此问题,因此建议将其放入 ng-src 指令中,但我在它上面使用了一个助手,它给出了我这个错误。这是我的代码:

= image_tag nil, "ng-src" => asset_path(:images, "{{phone.imageUrl}}")

【问题讨论】:

    标签: javascript angularjs sprockets middleman


    【解决方案1】:

    image_tag 助手在任何情况下都添加了src 属性(参见http://www.padrinorb.com/api/Padrino/Helpers/AssetTagHelpers.html#image_tag-instance_method,点击“查看源代码”):

    # File 'padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb', line 253
    
    def image_tag(url, options={})
      options.reverse_merge!(:src => image_path(url))
      tag(:img, options)
    end
    

    由于 image_tag 在内部仅使用 tag 帮助器,您可以通过 ... 实现您的结果。

    = tag :img, "ng-src" => asset_path(:images, "{{phone.imageUrl}}")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      相关资源
      最近更新 更多