【问题标题】:How to give a link to .pdf file in html for angularjs? ng-src如何在 html 中为 angularjs 提供指向 .pdf 文件的链接? ng-src
【发布时间】:2014-07-22 06:30:49
【问题描述】:

这是我的 app.js 文件中的产品详细信息。

{
code:'18471IN-4-CP',
name:'Symbol Bath and Shower Trim',
price:22875.95,
description:'Symbol recessed bath and shower faucet trim with lever handle and diverter button.',
specification:'These are the new specs from json.',
canPurchase:true,
soldOut:false,
images:[
    {
        full:'BathTub.jpg',
        thumb:'Pipe.jpg'
    },
    {
        full:'Shower Trim1.jpg',
        thumb:'Pipe1.jpg'
    }
],
technicalDetail:'6311W-926.pdf',
cadDrawing: 'k_6311w_0.dwg'
},

下面的 html 代码根据 app.js 中的 json var 详细信息从 img 文件夹加载图像

<img ng-src="img/{{product.images[0].thumb}}">

如何放置允许下载 pdf 的链接(pdf 文件夹中的 6311W-926.pdf)或任何其他文件扩展名?

类似 --- ng-src="pdf/{{product.technicalDetail}}"

【问题讨论】:

    标签: javascript html angularjs pdf


    【解决方案1】:

    试试这个:

    <a ng-href="pdf/{{product.technicalDetail}}" target="_blank"> download pdf </a>
    

    【讨论】:

    • 有没有可能不是在 html 文件中定义文件夹 pdf/... ,而是将路径本身存储在 json 中,即到 app.js 文件中?
    • @Optimight 我认为您应该在 json 中拥有文件的完整路径,而不仅仅是名称。修改json,如下所示:{ TechnicalDetail: 'pdf/6311W-926.pdf' }
    • 因为你在href里面有角度绑定,你应该使用ng-href而不是href。 docs.angularjs.org/api/ng/directive/ngHref
    猜你喜欢
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 2017-10-07
    相关资源
    最近更新 更多