2016-04-29 33 views
0

我有一個儀表板,我可以創建列表並將它們打印在短劃線上,但是當我點擊其中任何一個時,它只會打開最後創建一個。我究竟做錯了什麼?我正在使用最新的Angular,Firebase和AngularFire。點擊舊列表只顯示上次創建的ID,應該顯示列表ID點擊

我的代碼看起來像這樣,以創造和開放的功能:

allLists = new Firebase('https://url.firebaseio.com/lists/' + authData.uid); 

// Modal service for creating a new list 
    $scope.createList = function(){ 
     newList = allLists.push({ 
     name: 'new list' 
     }); 
     listUID = newList.key(); 
     $rootScope.listUID = new Firebase('https://url.firebaseio.com/lists/' + authData.uid + '/' + listUID); 

     // Runs the ngDialog scheme with template etc 
     ngDialog.open({ 
     template:'user-modal.html', 
     controller: 'createController', 
     scope: $scope, 
     className:'ngdialog-theme-default' 
     }); 
     console.log('listUID is: ' + listUID); 
     return listUID; 
    }; 

// Modal service for opening an old list for edit/remove/whatnot 
    $scope.openList = function(index){ 
    oldUID = new Firebase('https://url.firebaseio.com/lists/' + authData.uid + '/' + listUID); 

    ngDialog.open({ 
     template: 'user-old-list.html', 
     controller: 'oldListController', 
     className: 'ngdialog-theme-default', 
     scope: $scope 
     }); 
     console.log(listUID); 
    }; 

通過簡單的HTML作爲本:

<div ng-repeat="(id, lists) in listCounter" class="user-lists"> 
    <button ng-click="openList()" ng-model="listCounter[id]">{{lists.$id}}<br />{{lists.name}}</button> 
</div> 

其中提到:

$rootScope.listCounter = $firebaseArray(allLists); 
+0

我們可以看到完整的'ng-repeat'代碼嗎? –

+0

@MuliYulzary '

' 另外: '$ rootScope.listCounter = $ firebaseArray(allLists);' – mtorn

+0

您可以編輯帖子以便閱讀嗎? –

回答

0

你是沒有通過idopenList()。在模板中嘗試ng-click="openList(id)"。你也不會在你的函數的任何地方引用索引。

+0

如何以及應該在哪裏提及索引? – mtorn

+0

如果我將它設置爲openList = function(id),它只會指向最後創建的id,而不是我點擊的那個id。 :/ – mtorn

+0

我對Firebase沒有多少經驗,但是在控制器的'openList'中。可能要更改'oldUID = new Firebase('https://url.firebaseio.com/lists/'+ authData.uid +'/'+ listUID);'到特定於您要顯示的列表的某個網址。 –