gpt4 book ai didi

angularjs - AngularJS 中 "href"和 "ng-href"的区别

转载 作者:行者123 更新时间:2023-12-03 11:48:07 24 4
gpt4 key购买 nike

我都用过 hrefng-href我看不出它们之间的区别。

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

最佳答案

From the documentation:

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 .

关于angularjs - AngularJS 中 "href"和 "ng-href"的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37467603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com