大佬教程收集整理的这篇文章主要介绍了Angular框架中当前页面跳转,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我们在使用 $routeProvider后,想在当前页面中跳转连接,往往得不到正确的跳转。
例如:
test.html
<a href="#faq-1">Question 1</a>
<a href="#faq-2">Question 2</a>
<a href="#faq-3">Question 3</a>
<h3 id="faq-1">Question 1</h3>
<h3 id="faq-2">Question 2</h3>
<h3 id="fa1-3">Question 3</h3>
由于 我们可能设置了 $routeProvider
app.js
var app = angular.module('angularjs-starter',[]);
app.config(function($routeProvider) {
$routeProvider.when('/test',{
controller: 'TESTCtrl',templateUrl: 'test.html'
})
.when('/weee',{
controller: 'WeeeCtrl',templateUrl: 'weee.html'
})
.otherwise({
redirectTo: '/test'
});
});
app.run(function($rootScope,$LOCATIOn,$anchorScroll) {
//when the route is changed scroll to the proper element.
$rootScope.$on('$routeChangesuccess',function(newRoute,oldRoutE) {
if($LOCATIOn.hash()) $anchorScroll();
});
});
<a href="#/test#foo">Test/Foo</a>
但是会刷新的整个页面
<a href="#faq-1" target="_self">Question 1</a>
这个方法简单有效!
http://stackoverflow.com/questions/14712223/how-to-handle-anchor-hash-linking-in-angularjs
以上是大佬教程为你收集整理的Angular框架中当前页面跳转全部内容,希望文章能够帮你解决Angular框架中当前页面跳转所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。