简体   繁体   English

在角度js {{i.link}}中,元素a的属性href显示w3c验证错误

[英]In angular js {{i.link}} for attribute href on element a showing w3c validation error

My Html code with Angular js: 我的带有Angular js的Html代码:

<li data-ng-repeat="i in items | searchFor:searchString | limitTo:limit" >
                        <p><a href="{{i.link}}" class="search-link">{{i.title}}</a></p>
                        <p>{{i.description}}</p>
                        <p><a class="small" href="{{i.link}}">{{i.link}}</a></p>                
                    </li>

W3c Validation giving error like below : W3c验证给出如下错误:
Bad value {{i.link}} for attribute href on element a: Illegal character in path segment: { is not allowed. 元素a上属性href的值{{i.link}}错误:路径段中的非法字符:{不允许。

Use ng-href for this. 为此使用ng-href。 Angular will transform it to the correct value. Angular会将其转换为正确的值。

https://docs.angularjs.org/api/ng/directive/ngHref https://docs.angularjs.org/api/ng/directive/ngHref

Finally - using data-ng-href will solve the problem with validation problems. 最后 - 使用data-ng-href将解决验证问题。 (Related SO question What is the difference between ng-app and data-ng-app? ) (相关问题请问ng-app和data-ng-app有什么区别?

You should use ngHref . 你应该使用ngHref That is what AngularJS recommends. 这就是AngularJS推荐的内容。 The W3C validation error will also get resolved. W3C验证错误也将得到解决。 Also if you use href there will be issue of broken link. 此外,如果您使用href ,将会出现链接断开的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM