angular.module('example').service('myService', function
myService($rootScope,$route,$http,$location) {
$("#mainwindowscroll").on('scroll', function (e) {
$location.path('/about');
});
});
Asked
Active
Viewed 224 times
-3

Lucky
- 16,787
- 19
- 117
- 151

Niraj Kashyap
- 232
- 2
- 8
-
what is $location value ??? – Bhojendra Rauniyar Aug 20 '14 at 05:57
-
$location.path = 'about' ???? – Bhojendra Rauniyar Aug 20 '14 at 05:58
-
You should create a directive to perform this kind of action. If you are coming from jQuery, you can read this http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background – apairet Aug 20 '14 at 06:04
-
@C-linkNepal angular guy will know that what is $location . – Niraj Kashyap Aug 20 '14 at 07:03
2 Answers
0
The first reason it doesn't work is - jquery is not part of angular digest mechanism.
To make it work you should apply the location change:
$rootScope.$apply(function() {
$location.path('/about');
});
Also, make sure the location (/about) is defined in your app module. Otherwise you can use
$window.location('about')
to navigate to a complete different path (don't forget injecting $window of course).

Tomer
- 4,382
- 5
- 38
- 48
-
thanks. location (/about) is defined in my app module. I tried `$rootScope.$apply(function() { $location.path('/about'); }); ` that solve the issue thanks again – Niraj Kashyap Aug 20 '14 at 07:05