在Angular中使用哈希或javascript的空锚标记值

时间:2022-11-27 18:00:15

We're trying to come up to speed with Angular.js and our lead JS dev has requested that when we mock up links that don't yet have a page to go to, we should do the following:

我们正试图加快Angular.js的速度,我们的主要JS开发人员已经要求当我们模拟尚未有页面的链接时,我们应该执行以下操作:

<a href="javascript://">

instead of this:

而不是这个:

<a href="#">

His reasoning was that Angular already has a use for the hash tag because it means something to Angular and if it doesn't find the router/directive then it is redirected to /scenario.

他的理由是Angular已经使用了hash标签,因为它对Angular有意义,如果找不到路由器/指令,那么它会被重定向到/ scenario。

What is a better way to do this?

有什么更好的方法呢?

1 个解决方案

#1


8  

According to the AngularJS docs for the A directive, you should be using href="".

根据A指令的AngularJS文档,您应该使用href =“”。

The reasoning for this is to allow easy creation of action links with ngClick directive without changing the location or causing page reloads, e.g.: <a href="" ng-click="model.$save()">Save</a>

这样做的原因是允许使用ngClick指令轻松创建操作链接,而无需更改位置或导致页面重新加载,例如:保存

#1


8  

According to the AngularJS docs for the A directive, you should be using href="".

根据A指令的AngularJS文档,您应该使用href =“”。

The reasoning for this is to allow easy creation of action links with ngClick directive without changing the location or causing page reloads, e.g.: <a href="" ng-click="model.$save()">Save</a>

这样做的原因是允许使用ngClick指令轻松创建操作链接,而无需更改位置或导致页面重新加载,例如:保存