gpt4 book ai didi

javascript - 添加 anchor 到 AngularJS State

转载 作者:行者123 更新时间:2023-12-03 05:32:14 24 4
gpt4 key购买 nike

我有一个名为 state.home() 的状态,用于将用户重定向到主页,这是我的状态:

$stateProvider
.state('state.home', {
url: '/home',
templateUrl: modulePath + '/views/home/home.html',
controller: 'state:HomeController',
controllerAs: 'homeCtr'
})

在完成一些工作后的另一个页面中,在我的 Controller 中,我需要将用户重定向到主页中的特定 Div,因此在我的 Controller 中,我添加了这一行用于重定向,但它似乎不正确方式:

$state.go('state.home',{'#': 'anchor'});

我想知道它是否可以在相同的状态下工作,或者我必须创建一个新的状态。

最佳答案

给div一个id,例如<div id="anchor"></div>

在 Controller 中,导航到预期状态并使用 anchor 滚动转到 div。不要忘记注入(inject)$anchorScroll

$state.go('state.home').then(function() {$anchorScroll('anchor');})

关于javascript - 添加 anchor 到 AngularJS State,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40894810/

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