如何在绝对URL中使用ng-href? [英] How to use ng-href with absolute url?

查看:65
本文介绍了如何在绝对URL中使用ng-href?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对angularjs还是很陌生,但有一个问题,就是我似乎找不到解决方法,而且我没有时间去研究角度源.

I'm still new to angularjs, and I have a problem that I seem to not be able to find solution, and I don't have time to go look into angular source.

这是我的情况:

我有一些要在屏幕上显示的带有url集合的json数据. 我有一个ng-repeat="link in links"元素,里面有

I have some json data with collection of urls that I want to show on screen. I have an element with ng-repeat="link in links" and inside I have

<a ng-href="{{link.url}}">{{link.title}}</a>

可以,但是所有链接都指向 mydomain/apppath/ valueoflink.title 我希望它们是绝对的,只有 valueoflink.title ,没有任何前缀.

That works, but all links are pointing to mydomain/apppath/valueoflink.title I want them to be absolute, only valueoflink.title without any prefix.

如何告诉angular它是绝对的非相对URL?

How to tell angular that it is absolute not relative url?

推荐答案

我通过在json中的数据前面加上"http://"使它们成为真正的绝对URL来解决它,而angularjs对此表示尊重.

I solved it by prefixing data in json with 'http://' to make them trully absolute urls, and angularjs respects that.

然后我了解到angular实际上并没有对价值做任何事情,只是按原样放置它,这是我的错.

Then I understood that angular is actually not doing anything with value, it is just putting it there as it is, and it is my fault to see that.

为此更新代码可以解决所有网址都类似于"www.google.com"的问题

updating code to this solves problem when all urls are like 'www.google.com'

<a ng-href="http://{{link.url}}">{{link.title}}</a>

发现了一个古老的检查元素",我忽略了ng-href从{{value}}语法绑定的事实,因此这就是为什么我第一次尝试放置ng-href="'http://'+{{value}}"失败并导致我提早提问题的原因,但我不确定是否应该删除它,因为我可能不仅是犯此类错误的人.

Plain old 'inspect element' uncovered issue, and I ignored the fact that ng-href binds from {{value}} syntax, so this is why my first attempt to put ng-href="'http://'+{{value}}" failed and led me to ask question prematurely, but I'm not sure if I should delete it as I may not be only one making such mistake.

这篇关于如何在绝对URL中使用ng-href?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆