与AngularJS SammyJS [英] SammyJS with AngularJS
本文介绍了与AngularJS SammyJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用萨米与角度的问题。
I have problems using Sammy with Angular.
我有这样的应用模块
var appModule = angular.module('myApp', []).run(function (routes) {
routes.run('#/');
});
和此服务
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;
});
我需要这个的setTimeout
,因为我不知道什么时候$ rootScope访问。当我把在的setTimeout
低区间数,事件不会播出。间隔一秒工程确定,但我不希望这样丑陋的解决方案。我怎样才能确保$ rootScope已准备就绪,我可以启动URL处理函数?
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?
推荐答案
你真的需要使用萨米
您是否尝试过采用了棱角分明的路由来获取参数?
Have you tried using Angular's routing to get the parameters?
见
http://docs.angularjs.org/api/ng.$route
和
http://docs.angularjs.org/api/ng.$routeParams
欢呼
斯图
这篇关于与AngularJS SammyJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文