我是angularjs的新成員,並且正在與firebase一起玩耍。我遵循隱含同步的 angularFire tutorial。當第二次加載控制器時,angularFire()返回undefined
我的控制器代碼是
trankeeloManagerApp.controller('StoresCtrl', [
'NavService', '$scope', 'angularFire',
function(NavService, $scope, angularFire) {
NavService.updateActiveNav();
var url = '[MY_URL]/users/test_user/stores';
$scope.stores = angularFire(url, $scope, 'stores', []);
$scope.store = {
name: '',
tin: '',
description: ''
};
$scope.page = {
show_list_loading : true,
show_list_table : false,
show_list : true,
show_add_item : false,
show_add_button : false,
};
$scope.stores.then(function(stores) {
$scope.hideList();
console.log(stores);
$('#datatables').dataTable({
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
},
"aaData" : $scope.stores,
"aoColumns": [
{ "sTitle": "Name", "mData": "name", "mDataProp" : "name" },
{ "sTitle": "TIN", "mData": "tin", "mDataProp" : "tin" },
{ "sTitle": "Description", "mData": "description", "mDataProp" : "description" }
]
});
$scope.page.show_add_button = true;
$scope.addStore = function(){
$scope.showList();
$scope.stores.push($scope.store);
addStoreInDatatable($scope.store);
$scope.store = {
name: '',
tin: '',
description: ''
};
};
$scope.removeStore = function (store) {
$scope.stores.splice($scope.stores.indexOf(store), 1);
};
//TODO implement edit
});
$scope.showAddStore = function(){
$scope.page.show_add_item = true;
$scope.page.show_list = false;
}
$scope.cancelAddStore = function(){
$scope.hideList();
}
$scope.showList = function(){
$scope.page.show_add_item = false;
$scope.page.show_list = true;
};
$scope.hideList = function(){
$scope.page.show_list_loading = false;
$scope.page.show_list_table = true;
};
function addStoreInDatatable(store){
$('#datatables').dataTable().fnAddData({
"name" : store.name,
"tin" : store.tin,
"description" : store.description
});
};
$scope.showList();
}]);
一切運作良好的第一負載,但是當我去到另一個控制器並返回。我得到這個錯誤。
TypeError: Cannot call method 'then' of undefined
我試着調試代碼,它指向這個方法'_safeApply'。 當'fn();'被調用時,它是未定義的,我對新的js,所以這是儘可能我現在可以去。當我醒來時,我會盡量多看看這個 – 2013-04-06 23:27:13
好的問題是,如果值本地高速緩存,值處理程序將被同步調用。托馬斯已經正確識別了這個問題,我很快就會合並修復! – Anant 2013-04-08 06:56:18