2016-04-29 60 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);'到特定于您要显示的列表的某个网址。 –