Javascript $location.path()在滚动绑定中不起作用
它不起作用的第一个原因是-jquery不是angular digest机制的一部分。 要使其正常工作,您应应用位置更改:Javascript $location.path()在滚动绑定中不起作用,javascript,angularjs,angularjs-directive,ngroute,angularjs-ng-route,Javascript,Angularjs,Angularjs Directive,Ngroute,Angularjs Ng Route,它不起作用的第一个原因是-jquery不是angular digest机制的一部分。 要使其正常工作,您应应用位置更改: angular.module('example').service('myService', function myService($rootScope,$route,$http,$location) { $("#mainwindowscroll").on('scroll', function (e) {
angular.module('example').service('myService', function
myService($rootScope,$route,$http,$location) {
$("#mainwindowscroll").on('scroll', function (e) {
$location.path('/about');
});
});
此外,请确保在应用程序模块中定义了位置/关于。否则,您可以使用
$rootScope.$apply(function() {
$location.path('/about');
});
要导航到一个完全不同的路径,当然不要忘记注入$window。请确保您已经为导航url“/about”配置了路由?什么是$location value???$location.path='about'?您应该创建一个指令来执行这种操作。如果你来自jQuery,你可以阅读这个@C-link,他会知道什么是$location。谢谢。位置/关于在我的应用程序模块中定义。我尝试了$rootScope.$applyfunction{$location.path'/about';};这解决了问题,再次感谢
$window.location('about')