简体   繁体   English

Angular.ui-将数据传递给模态时出错

[英]Angular.ui - Error passing data to modal

I've created a modal to edit objects in a list. 我创建了一个模态来编辑列表中的对象。 Here is the list: 这是清单:

<div class="container">
  <label class="text-center">Previous Grades</label>
  <table class="table">
    <th ng-repeat="head in tableHeadings"> {{head}}</th>
    <tr ng-repeat="gr in grades track by $index" >
      <td > {{gr.name}}</td>
      <td>{{gr.teacher}}</td>
      <td> {{gr.score}}</td>
      <td><button class="btn btn-info btn-sm" ng-click="open($index)"><span class="glyphicon glyphicon-pencil"></span></button></td>
    </tr>
  </table>
</div>

Here is the function that opens modal: 这是打开模式的函数:

$scope.open = function (index) {
      var modalInstance = $modal.open({
        templateUrl: '../views/modalEdit.html',
        controller: 'modalInstanceController',
        resolve: {
          items: function () {
            return $scope.grades;
          },
          index: function (){
            return index;
          }
        }
      })

And here is the modal controller: 这是模态控制器:

.controller('modalInstanceController', function ($scope, $modalInstance, grades, index) {
    $scope.grades = grades;
    $scope.index = index;

    $scope.gradeEditing = $scope.grades[index];

    $scope.ok = function(){
      $modalInstance.close();
    };
    $scope.cancel = function(){
      $modalInstance.dismiss('cancel');
    }
  });

I'm getting a $injector error! 我收到$ injector错误! I injected the resolve values but it still doesn't work :/ That's the error i'm getting: 我注入了解析值,但仍然不起作用:/这就是我得到的错误:

>  Error: [$injector:unpr] Unknown provider: gradesProvider <- grades
http://errors.angularjs.org/1.3.4/$injector/unpr?p0=gradesProvider%20%3C-%20grades

Any ideas? 有任何想法吗?

That is because you defined the "grades" in resolve as "items", not grades: 这是因为您在解析中将“成绩”定义为“项目”,而不是成绩:

    resolve: {
      items: function () {
        return $scope.grades;
      },
      index: function (){
        return index;
      }
    }

Make it the following and it will work: 使其符合以下条件,它将起作用:

    resolve: {
      grades: function () {
        return $scope.grades;
      },
      index: function (){
        return index;
      }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM