"href"与"href"之间的区别在于和"ng-href"在AngularJS中 [英] Difference between "href" and "ng-href" in AngularJS

查看:100
本文介绍了"href"与"href"之间的区别在于和"ng-href"在AngularJS中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时使用了hrefng-href,但看不到它们之间的区别.

I've used both href and ng-href and I couldn't see the difference between them.

为什么Angular具有ng-href属性,我什么时候应该使用它?

Why does Angular have the ng-href attribute, and when should I use it?

推荐答案

从文档中:

在href属性中使用{{hash}}之类的Angular标记会使链接转到错误的URL(如果用户在Angular有机会将{{hash}}标记替换为其值之前)单击该链接.在Angular替换标记之前,链接将断开,并且很可能会返回404错误. ngHref指令解决了这个问题.

Using Angular markup like {{hash}} in an href attribute will make the link go to the wrong URL if the user clicks it before Angular has a chance to replace the {{hash}} markup with its value. Until Angular replaces the markup the link will be broken and will most likely return a 404 error. The ngHref directive solves this problem.

实际上,您唯一使用它的地方是链接,您需要依赖于Angular提供给DOM的值.如果您不需要该链接的一部分Angular,或者您不打算使用Angular来生成该链接,则不需要使用ngHref.

Effectively, the only place you're using it is for links in which you need to rely on a value provided to the DOM by Angular. If you do not require Angular for a part of that link, or you don't plan on using Angular to generate that link, then you do not need to use ngHref.

这篇关于"href"与"href"之间的区别在于和"ng-href"在AngularJS中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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