Angularjs 指令不求值 ~

Angularjs directives not evaluating ~

本文关键字:指令 Angularjs      更新时间:2023-09-26

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

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 中的"~"符号来解析图像路径。

知道吗?

我相信

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