Why ng-href behaving weird while parsing geo string

三世轮回 提交于 2019-12-19 10:23:04

问题


I've multiple geo string like geo:0,0q=1+a+bc, and I'm gonna assign this to ng-href of the anchor tag. Like below I'm doing it.

HTML

<a ng-href="{{geoString}}">Location</a> </br>

Above tag is rendering fine on HTML but adding unsafe: string geo:0,0q=1+a+bc inside href attribute

Rendered HTML

<a ng-href="geo:0,0q=12345+jefferson+st" href="unsafe:geo:0,0q=12345+jefferson+st">Location</a>

Plunkr with demonstrating issue.

I don't want unsafe: inside href, Any idea why it is pre-appending unsafe: before geoString & How do i remove it?


回答1:


You need to use aHrefSanitizationWhitelist([regexp]);

regex should match the url of your's So in your case it should be like

 $compileProvider.aHrefSanitizationWhitelist(/^\s*(geo):/);

regEx:- starting with geo followed by ' : '

Please see $compileProvider Documentation for more info.

Plunker



来源:https://stackoverflow.com/questions/28913139/why-ng-href-behaving-weird-while-parsing-geo-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!