单击旧列表只显示上次创建的id,应在单击时显示列表id

Clicking old list only shows last created id, should show the list-id im clicking

本文关键字:显示 id 列表 单击 创建      更新时间:2023-09-26

我有一个面板,可以在其中创建列表并将其打印在短划线上,但当我单击其中任何一个时,它只会打开上次创建的列表。我做错了什么?我正在使用最新的Angular、Firebase和AngularFire。

我的代码看起来像这样,带有创建和打开功能:

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);

您没有将id传递给openList()。尝试模板中的ng-click="openList(id)"。此外,您在函数中的任何位置都没有引用索引。