opitzconsulting / jquery-mobile-angular-adapter

jquery mobile angular adapter
MIT License
517 stars 114 forks source link

Emit route change events on the $rootScope #74

Closed mlegenhausen closed 11 years ago

mlegenhausen commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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

mlegenhausen commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

Of cause.