我是 angularjs 的新手,并且正在使用 firebase 来玩弄它。我正在关注 angularFire隐式同步教程。
我的控制器代码是
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:无法调用未定义的方法“then”