opitzconsulting / jquery-mobile-angular-adapter

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

$location service with require.js #191

Open bobbydams opened 11 years ago

bobbydams commented 11 years ago

Hallo Tobias, I'm migrating from JQM 1.1 of your adapter to the latest 1.3 and I have everything working the same except the $location service... I use requirejs to load in other scripts before changing the page. With $navigate this worked perfectly. Now with $location I have to call it twice before the page will actually change. Is there some way to force a page change? For example: require(['http://localhost/cdn/' + module + '/js/' + module + '.js'] , function() { $location.url('/' + view); $location.routeOverride({ templateUrl: '#' + view }); });

tbosch commented 11 years ago

Hi, you have to wrap the call to the $location service inside a $rootScope.$apply, as you are out of the normal control flow of angular (see here: http://docs.angularjs.org/guide/dev_guide.services.$location).

I.e. use

$rootScope.$apply(function() {
    $location.url(...);
});