0

私は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: undefined のメソッド 'then' を呼び出せません

4

1 に答える 1

4

現在バグがあったと思うのと同じ動作を経験していますangularFire.js

要求された値がすでにローカルにキャッシュされている場合は、(解決された) promise の代わりにangularFire()戻ります。undefined

更新:バグは修正されました。

への後続の呼び出しに関する問題について$scope.stores.push:バインドされた値(angularFire()の3番目の引数で指定)とバインディングの約束(angularFire()によって返される)を区別することをお勧めします。

$scope.promise = angularFire(url, $scope, 'stores', []);
$scope.promise.then (function () {
    $scope.stores = { foo: 'bar', ... };
});
于 2013-04-07T17:57:22.460 に答える