问题
I have a link tag in HTML:
<link url="http://google.com">google</link>
and code that transform it to <a>
tag:
app.directive('link', function() {
return {
restrict: 'E',
transclude: true,
replace: true,
scope: {
url: '@'
},
template: '<a href="{{url}}" ng-transclude></a>'
}
});
But using this text Google is outside and URL is not removed (it copy if from link to a tag). If I use an attribute it works fine <div link url="http://google.com">google</div>
What's wrong?
Here is
jsFiddle.
回答1:
I think I know the reason for this, the link
if html tag (that from head to include stylesheet) that is single self closing tag, and it seams that how parser parse it before Angular is executed.
来源:https://stackoverflow.com/questions/18268090/text-inside-tag-outside-of-output-tag-in-angular-js