Emit route change events on the $rootScope #74

Closed
mlegenhausen opened this Issue Nov 27, 2012 · 10 comments

Comments

Projects
None yet
2 participants
@mlegenhausen

It would be nice if something like the $routeChangeSuccess in angular.js could be emitted on page change of jqm. A use case is tracking the user position in the app from a central place (google analytics). This is of cause only needed when you do not use the routeProvider from angular.

Maybe I could work something out.

@tbosch

This comment has been minimized.

Show comment Hide comment
@tbosch

tbosch Nov 28, 2012

Contributor

Hi,
with the issue #59 (which is almost done) I change the hash listening to completly use angular routes. By this, you can use that exact $routeChangeSuccess event from angular. You could try using the current 1.1.2-SNAPSHOT version.
However, you can always use the jquery mobile event pagebeforeshow (see http://jquerymobile.com/demos/1.2.0/docs/api/events.html).

Do you need more information? Otherwise I would close this ticket...

Tobias

Contributor

tbosch commented Nov 28, 2012

Hi,
with the issue #59 (which is almost done) I change the hash listening to completly use angular routes. By this, you can use that exact $routeChangeSuccess event from angular. You could try using the current 1.1.2-SNAPSHOT version.
However, you can always use the jquery mobile event pagebeforeshow (see http://jquerymobile.com/demos/1.2.0/docs/api/events.html).

Do you need more information? Otherwise I would close this ticket...

Tobias

@mlegenhausen

This comment has been minimized.

Show comment Hide comment
@mlegenhausen

mlegenhausen Nov 28, 2012

This sounds good, I will try it out and give you feedback. Thanks!

This sounds good, I will try it out and give you feedback. Thanks!

@mlegenhausen

This comment has been minimized.

Show comment Hide comment
@mlegenhausen

mlegenhausen Nov 28, 2012

I have problems when using the new SNAPSHOT when fetching the $rootScope via an injector following jsfiddle demonstrates the error: http://jsfiddle.net/pbcy3/1/. This worked with the previous version.

This is not releated to the event emitting maybe we should open a new issue?

I have problems when using the new SNAPSHOT when fetching the $rootScope via an injector following jsfiddle demonstrates the error: http://jsfiddle.net/pbcy3/1/. This worked with the previous version.

This is not releated to the event emitting maybe we should open a new issue?

@tbosch

This comment has been minimized.

Show comment Hide comment
@tbosch

tbosch Nov 28, 2012

Contributor

Hi,
this is not a bug, and also occurs if you use plain angular, see here: http://jsfiddle.net/D3Wdp/

Problem is that if you directly create an injector, and want to access the $rootElement (which is used by $route which is used by the adapter), you have to create a service for this. If you use the normal angular-js bootstrapping, angular will provide this service for you. In unit-tests, you should use angular-mocks.js (see the angular-js distribution), which also provides a $rootElement service.

Tobias

Contributor

tbosch commented Nov 28, 2012

Hi,
this is not a bug, and also occurs if you use plain angular, see here: http://jsfiddle.net/D3Wdp/

Problem is that if you directly create an injector, and want to access the $rootElement (which is used by $route which is used by the adapter), you have to create a service for this. If you use the normal angular-js bootstrapping, angular will provide this service for you. In unit-tests, you should use angular-mocks.js (see the angular-js distribution), which also provides a $rootElement service.

Tobias

@mlegenhausen

This comment has been minimized.

Show comment Hide comment
@mlegenhausen

mlegenhausen Nov 28, 2012

That is strange, cause with 1.1.1 of jqm-angular it is working: http://jsfiddle.net/pbcy3/2/ So my app currently depends on it.

That is strange, cause with 1.1.1 of jqm-angular it is working: http://jsfiddle.net/pbcy3/2/ So my app currently depends on it.

@tbosch

This comment has been minimized.

Show comment Hide comment
@tbosch

tbosch Nov 28, 2012

Contributor

The change in 1.1.2 is to use $route of angular, which depends on $rootElement. 1.1.1 did not use $route, and you probably also did not use it, so you did not get that error.
Anyway, if you are bootstrapping you application using a manual call to angular.injector, you have to provide the $rootElement by yourself. This is not a requirement of the adapter, but of angular itself as soon as you use $route of angular.

Could you give some details about how your are bootstrapping your application? The recommended ways for bootstrapping an angularjs application are these ones: http://docs.angularjs.org/guide/bootstrap (an automatic one using ng-app directive, or a manual one using angular.bootstrap).

Tobias

Contributor

tbosch commented Nov 28, 2012

The change in 1.1.2 is to use $route of angular, which depends on $rootElement. 1.1.1 did not use $route, and you probably also did not use it, so you did not get that error.
Anyway, if you are bootstrapping you application using a manual call to angular.injector, you have to provide the $rootElement by yourself. This is not a requirement of the adapter, but of angular itself as soon as you use $route of angular.

Could you give some details about how your are bootstrapping your application? The recommended ways for bootstrapping an angularjs application are these ones: http://docs.angularjs.org/guide/bootstrap (an automatic one using ng-app directive, or a manual one using angular.bootstrap).

Tobias

@mlegenhausen

This comment has been minimized.

Show comment Hide comment
@mlegenhausen

mlegenhausen Nov 28, 2012

In my case I do some application setup at the start of the application before I am bootstraping angular. I am using angularjs DI for managing my dependencies, that why I am creating a separate injector. The $rootScope is needed cause I am using $q for async database access and the deffered resolve and reject method are only triggered after an $apply call. I think I will move the setup part in the main application, which will also increase the startup time.

In my case I do some application setup at the start of the application before I am bootstraping angular. I am using angularjs DI for managing my dependencies, that why I am creating a separate injector. The $rootScope is needed cause I am using $q for async database access and the deffered resolve and reject method are only triggered after an $apply call. I think I will move the setup part in the main application, which will also increase the startup time.

@mlegenhausen

This comment has been minimized.

Show comment Hide comment
@mlegenhausen

mlegenhausen Nov 29, 2012

Ok I solved the $rootScope problem and changed to the new 1.1.2 SNAPSHOT. Now I have problems with the new $navigate. When I try to navigate through my app the navigation always jumps back to the first page after a second click and with ng-click the app is broken. Fiddle: http://jsfiddle.net/ZHKBA/63/

Ok I solved the $rootScope problem and changed to the new 1.1.2 SNAPSHOT. Now I have problems with the new $navigate. When I try to navigate through my app the navigation always jumps back to the first page after a second click and with ng-click the app is broken. Fiddle: http://jsfiddle.net/ZHKBA/63/

@tbosch

This comment has been minimized.

Show comment Hide comment
@tbosch

tbosch Nov 29, 2012

Contributor

Hi,
thanks for reporting this. This really seems to be a bug that was introduced by 1.1.2-SNAPSHOT. Could you create a new issue for that bug and close this issue?

Thanks,
Tobias

Contributor

tbosch commented Nov 29, 2012

Hi,
thanks for reporting this. This really seems to be a bug that was introduced by 1.1.2-SNAPSHOT. Could you create a new issue for that bug and close this issue?

Thanks,
Tobias

@mlegenhausen

This comment has been minimized.

Show comment Hide comment
@mlegenhausen

mlegenhausen Nov 29, 2012

Of cause.

Of cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment