Javascript Angularjs指令不计算~

Javascript Angularjs指令不计算~,javascript,angularjs,angularjs-directive,angularjs-scope,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Ng Repeat,我有一个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())(sc

我有一个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}

当你使用~,我可以问一下你在找什么吗?如果您想要一个与使用该指令的当前页面/URL相关的图像,可以直接使用img/Logo/{{{account.Logo}}。理想情况下,在ng src指令中应该有一个逻辑来为应用程序的基本URL添加前缀。