Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript href使用Angularjs和Twitter引导程序导致意外页面重新加载_Javascript_Html_Twitter Bootstrap_Angularjs_Href - Fatal编程技术网

Javascript href使用Angularjs和Twitter引导程序导致意外页面重新加载

Javascript href使用Angularjs和Twitter引导程序导致意外页面重新加载,javascript,html,twitter-bootstrap,angularjs,href,Javascript,Html,Twitter Bootstrap,Angularjs,Href,我正在做一个使用Angularjs和Twitter引导的项目 Bootstrap使用#切换popover、modal等组件。 例如: <a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a> <!-- Modal --> <div id="myModal" class="modal hide fade" tabindex="-1" rol

我正在做一个使用Angularjs和Twitter引导的项目

Bootstrap使用#切换popover、modal等组件。 例如:

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>
按钮的href是

href="#myModal"
我希望看到url

localhost:8080/#/account#myModal
然而,我看到的是

localhost:8080/#myModal
我不确定这是否与我的问题有关

提前谢谢

编辑1

我看到了斯图维谈论的另一篇帖子。它在angularjs中解释了html5mode和hashbang,但它并没有真正解决我的问题


我尝试使用HTML5模式,但当我点击按钮时,它仍然会重新加载页面。继续并进行以下更改,将javascript:void(0)而不是#myModal for href。使用Javascript通过点击事件触发模式打开

    <a href="javascript:void(0)" onClick="openModal()" role="button"...

    function openModal(){
      $("#myModal").moda();
    }

角度的hashbang用于。请阅读本教程,以更深入地了解其工作原理

你也应该看一看

常规Boostrap并没有考虑到角度,所以很少有东西不符合角度。因此,团队决定将Boostrap移植到Angular指令中,让您能够充分利用Angular的
ng-
功能(仅使用常规Boostrap无法轻松实现)


由于路由的工作方式,我认为你不能做你想做的事情,你也不需要这样做。由于将
用作按钮,请将其设置为常规按钮并添加
ng单击按钮

<button class="btn btn-primary" ng-click="openDialog()">Open Dialog</button>

我也遇到过类似的问题,整版重新加载与视图切换

因为Angular应用程序是SAP,所以我们只更新hostname/#/之后的内容

我实例化了一个超级控制器,一种应用程序级控制器,正如Carlos V所说,您可以使用ng click而不是href来更新
$location.path()

这是一把小提琴


可能不是最理想的解决方案。希望有帮助。

这是因为HTML链接重写了Angular,解释道

要防止位置重写,请将
target=\u self
添加到这些引导链接

因此,您需要的不是
,而是

我解决了: 只需通过DATA-TARGET属性更改HREF属性即可


  • 轮廓
门斜颈 杜伊斯·莫利斯,这不是康莫多
在你的js中使用类似的东西

$('a').on('click',function(e){

    e.preventDefault();
});

只需确保为您的“a”创建一个类,否则您将为所有a创建一个类。

这里有一个更简单的解决方案:


只需将
target=“\u self”
添加到您的链接中

具有明确定义的内部导航页面语义角色时,您为什么要使用它?它不是指向资源的链接,为什么不直接使用
?可能的重复项您是否查看了
数据目标
选项?通过这种方式,您可以让angular选择href。这似乎可以防止Android 2.3.x浏览器中的ng click操作。谢谢,这可能是最简单的解决方案!谢谢你,你节省了我的时间:)在Angular 7上做得很好。
<a href="" ng-click="model.$save()">Save</a>
$('a').on('click',function(e){

    e.preventDefault();
});