I have problems using Sammy with Angular.
I have this application module
var appModule = angular.module('myApp', []).run(function (routes) {
routes.run('#/');
});
And this service
appModule.factory('routes', function ($rootScope) {
var routes = $.sammy(function () {
this.get('#/room/:roomId', function () {
var that = this;
setTimeout(function () {
$rootScope.$broadcast('user has entered the room', {roomId: that.params['roomId']});
}, 1000);
});
});
return routes;
});
I need this setTimeout
because I don't know when $rootScope is accessible. When I put low interval number in setTimeout
, event doesn't broadcasted. One second interval works OK, but I don't want such ugly solutions. How can I be sure that $rootScope is ready and I can launch url handler function?