问题
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