- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经尝试了这里提供的所有解决方案: How to handle anchor hash linking in AngularJS
但没有一个对我有用。
在我的 header.html
我有一个链接:<a id="button" href="#/views/home#page"> Contact</a></li>
到 home.html
中的 ID
当我在 /home
它有效,但是当我在另一个页面时它不起作用。
我尝试使用 ##page
没有成功。或者把它放在 app.js 中:
app.run(function($rootScope, $location, $anchorScroll, $routeParams) {
$rootScope.$on('$routeChangeSuccess', function(newRoute, oldRoute) {
$location.hash($routeParams.scrollTo);
$anchorScroll();
});
});
并自定义我的链接:
href="#/views/home/?scrollTo=page"
有人可以解释我应该编辑哪些文件以及如何编辑吗?
编辑:我从Angular-Seed开始
我的 app.js
是:
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myApp.view1',
'myApp.view2',
'myApp.training',
'myApp.faq',
'myApp.media',
'myApp.contact',
'myApp.home',
'myApp.apply',
'myApp.classes',
'myApp.version'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/views/home'});
}]);
在每个 View 中我都有另一个 js 文件,如 training.js
看起来像:
'use strict';
angular.module('myApp.training', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/views/training', {
templateUrl: 'views/training/training.html',
controller: 'TrainingCtrl'
});
}])
.controller('TrainingCtrl', [function() {
}]);
基于angular-seed模型配置。
所以,什么时候,我在视野中/faq
有部分 header
使用菜单和所有链接,我如何链接到 View 中的特定 ID /home
?
最佳答案
我认为问题在于您有逻辑滚动到 $routeChangeSuccess
中的那个散列,并且作为 documentation says, this event is :
Broadcasted after a route dependencies are resolved. ngView listens for the directive to instantiate the controller and render the view.
因此 View 尚未呈现,因此具有该 id 的 DOM 元素尚不存在。
尝试将该逻辑放入 ngView
directive 的 onload
事件中相反。
我创建了这个插件:http://plnkr.co/edit/S7bUT8iYY7UEti71X5Z8?p=preview这表明如果您将该逻辑添加到 ngView
directive 的 onload
事件中一切正常。
关于javascript - 从 AngularJS 中的另一个页面链接到 #ID 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25716936/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!