【问题标题】:Angularjs directives not evaluating ~Angularjs 指令未评估 ~
【发布时间】:2014-11-18 02:50:34
【问题描述】:

我有一个带有在链接器函数中编译的 html 模板的 angularjs 指令

var htmlTemplate = '<img ng-src="~/img/logos/{{account.Logo}}" width="45" height="35" />'

 var linker = function (scope, element) {

    element.html(htmlTemplate).show();
    $compile(element.contents())(scope);
};

但该指令并未评估 img src 中的“~”符号来解析图像路径。

有什么想法吗?

【问题讨论】:

    标签: javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat


    【解决方案1】:

    我相信您需要为 ng-src 指令使用绝对 URL,例如 ng-src="http://example.com/img/logos/{{account.Logo}}"

    【讨论】:

    • 请问你在找什么,当你使用“~”时?如果您想要一个相对于使用该指令的当前页面/URL 的图像,您可以直接使用img/logos/{{account.Logo}}。理想情况下,您应该在 ng-src 指令中添加一个逻辑,为应用的基本 URL (example.com) 加上前缀。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    相关资源
    最近更新 更多