2016-06-27 12 views
0

我試圖將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條款的對象,這樣我可以在一個數據表顯示,內一種模式形式。

現在,我成功彈出一個模態窗體,但無法獲取對象。

我在做什麼錯?

回答

0

您需要爲您的模式提供控制器名稱,https://angular-ui.github.io/bootstrap/#/modal請查閱文檔

+0

我已經過了,它是強制性的控制器嗎?如果是這樣,我可以得到一個示例控制器,如何使用它傳遞對象? 感謝您的快速回復,感謝它 –

+0

http://plnkr.co/edit/?p=preview – Grissom

+0

對不起,plunker預覽是爲了? –

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> 

我在哪裏翁? - >我的vm.userDetails是未定義的,但我試圖使用相同的HTML ng-repeat,

然後我定義它並分配了相同的scope.userDetails,value。

我研究了一下,發現,爲了實現我的目標,我真的不需要在uibModal中解析。

所以在這裏,我找到了解決方案,感謝所有試圖解決我的問題的人。希望這個答案有助於某人。

相關問題