传递一个对象并将其重新转换为角度模态

时间:2016-06-27 07:53:59

标签: angularjs json angularjs-ng-repeat angular-ui-bootstrap

我正在尝试将Objects传递给模态。我不知道如何将参数传递给模态。所以我正在尝试这个:

vm.viewGroupDetail = function(userDetails) {

    var scope = $scope.$new();
    scope.userDetails = userDetails;

    vm.modalInstance = $uibModal.open({
        animation: true,
        templateUrl: 'app/views/groups/group_details_modal.html',
        windowClass: 'd-modal',
        size: 'lg',
        scope: scope,
        resolve: {
            userDetails: function () {
                return $scope.userDetails;
            }
        }
    });



};

这是我的模态HTML:

<div class="modal-header portlet-title">
    <button type="button" class="close" aria-hidden="true" ng-click="$close()">&times;</button>
    <div class="caption font-dark">
        <span class="caption-subject bold uppercase"> Group Detail</span>
    </div>
</div>
<div class="modal-body">
     <div class="portlet light accordian-body inner-datatable" id="demo1">
          <div class="portlet-body custom-portlet">
            <table class="table table-striped table-bordered table-hover">
              <thead>
                <tr>
                  <th>Users </th>
                  <th> Designation </th>
                  <th> User Image </th>
                </tr>
              </thead>     
              <tbody>
              <tr ng-repeat="userdetail in userDetailsList">
                  <td> {{userdetail.fullName}}</td>
                  <td> {{userdetail.designation}} </td>
                  <td>  <div class="user-img-holder">{{userdetail.fullName}}</div></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
</div>
<div class="modal-footer col-center">
    <button type="button" class="btn btn-primary" ng-click="$close()">OK</button>
</div>

我想使用传递给ng-repeat子句的对象,这样我就可以在一个数据表中显示一个模态形式。

现在,我成功弹出一个模态表单,但无法获取对象。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

您需要为模态提供控制器名称,https://angular-ui.github.io/bootstrap/#/modal请查看文档

答案 1 :(得分:0)

很高兴我能得到答案,

我的模态功能如下,

vm.viewGroupDetail = function(userDetails) {

    var scope = $scope.$new();
    scope.userDetails = userDetails;
    vm.userDetails=userDetails;

    vm.modalInstance = $uibModal.open({
        animation: true,
        templateUrl: 'app/views/groups/group_details_modal.html',
        windowClass: 'd-modal',
        size: 'lg',
        scope: scope

    });



};

模态HTML:

<div class="modal-header portlet-title">
  <button type="button" class="close" aria-hidden="true" ng-  click="$close()">&times;</button>
  <div class="caption font-dark">
    <span class="caption-subject bold uppercase"> Group Detail</span>
  </div>
</div>
<div class="modal-body">
 <div class="portlet light accordian-body inner-datatable" id="demo1">
  <div class="portlet-body custom-portlet">
    <table class="table table-striped table-bordered table-hover">
      <thead>
        <tr>
          <th>Users </th>
          <th> Designation </th>
          <th> User Image </th>
        </tr>
      </thead>     
      <tbody>
        <tr ng-repeat="userdetail in vm.userDetails">
          <td> {{userdetail.fullName}}</td>
          <td> {{userdetail.designation}} </td>
          <td>  <div class="user-img-holder"><img ng-src="{{userdetail.userdetail.fullName}}" alt="user Image"></div></td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
</div>
<div class="modal-footer col-center">
  <button type="button" class="btn btn-primary" ng-click="$close()">OK</button>
 </div>

我哪里错了? - &GT;我的vm.userDetails未定义,但我试图使用相同的HTML ng-repeat,

然后我定义了它并分配了相同的scope.userDetails,value。

我研究了一下,并发现,为了实现我的目标,我真的不需要在uibModal中解决。

所以在这里,我找到了解决方案,感谢每一位试图解决我问题的人。希望这个答案可以帮助某人。