大佬教程收集整理的这篇文章主要介绍了angularjs – 如果我的url包含路由参数,则哈希链接重新路由为角,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以,如果im在页面国家,并点击链接#developing,那么页面将滚动到#developing而不重新路由,这是所需的.如果我在页面国家/地区,我点击#projects,页面将重新路由,然后滚动到#projects;我不想要重新路由发生.
这个问题只发生在大自然page1 / parameter#anchor的链接上,而不是简单的pageA#anchor.
主页的HTML代码段:
<ul> <li><a href="#/Country">Go to /Country</a></li> <li><a href="#/Country/US">Go to /Country/US</a></li> <li><a href="#/Country/Italy#Section-4">Go to /Country/Italy#Section-4</a></li> <li><a href="#/Country/Canada#Section-8">Go to /Country/Canada#Section-8</a></li> </ul>
<div id="Section-1" class="section pink"> Section 1 <div ng-if="country"> <a ng-href="#/Country/{{Country}}#Section-8">Go to /Country/{{Country}}#Section-8</a> </div> <div ng-if="!country"> <a ng-href="#/Country#Section-8">Go to /Country#Section-8</a> </div> </div>
所有JavaScript代码:
var app = angular.module("app",["ngRoute"]); app.config(["$routeProvider","$LOCATIOnProvider",function ($routeProvider,$LOCATIOnProvider) { $routeProvider .when("/",{ templateUrl: "./home-page.html",caseInsensitiveMatch: true,}) .when("/Home",}) .when("/Country",{ templateUrl: "./country-page.html",}) .when("/Country/:country",}) }]); countryController.$inject = ["$scope","$routeParams","$LOCATIOn","$anchorScroll"]; function countryController($scope,$routeParams,$LOCATIOn,$anchorScroll) { $scope.country = $routeParams.country; if (!!$LOCATIOn.$$hash) { $LOCATIOn.hash($LOCATIOn.$$hash); $anchorScroll(); } }
以上是大佬教程为你收集整理的angularjs – 如果我的url包含路由参数,则哈希链接重新路由为角全部内容,希望文章能够帮你解决angularjs – 如果我的url包含路由参数,则哈希链接重新路由为角所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。