简体   繁体   中英

Angular-ui-bootstrap modal not showing data passed to it

I am trying to pass some model data into a modal window when it opens. Its in a $http.post success and also in failure then() with some different titles and button texts. I pass multiple data to it like:

//.then(){...//same as below }
,function (response){
     $scope.PostRespData = response.data.message || 'Rq Failed';

     $scope.pn = $scope.PostRespData.substring(53,63);

     //(status=400) response modal string
     $scope.name = 'Hey there!';

     //modal options
     $scope.opts = {
                backdrop: true,
                backdropClick: true,
                dialogFade: false,
                keyboard: true,
                templateUrl : 'alreadyexists.html',
                controller : ModalInstanceCtrl,
                resolve: {}
                };


    $scope.opts.resolve.item = function() {
                   return angular.copy({name:$scope.name, errmsg:$scope.PostRespData, num:$scope.pn}); // pass name to modal dialo
                        }

     //open the modal and create a modal Isntance
     var modalInstance = $uibModal.open($scope.opts);

     var ModalInstanceCtrl = function($scope, $uibModalInstance, $uibModal, item) {

          $scope.item = item;

          $scope.ok = function () {
          $uibModalInstance.close();

          };

          $scope.cancel = function () {
          $uibModalInstance.close();
                        }

My HTML template looks like

<div class="modal-header">
  <h1>{{item.name}}</h1>
</div>
<div ng-controller="Nav" class="modal-body">
<p>{{item.errmsg}}
    <a href="http://myserver.com/page.jsp?num="+{{item.num}}+"&c=y">View {{item.num}}</a>
</p>
</div>
<div class="modal-footer">
  <button class="btn btn-primary" ng-click="ok()">Edit Current Details</button>
<button class="btn btn-warning" ng-click="cancel()">Edit {{item.num}}</button>
</div>

I get my modal and I also get the static data but data being passed to it does not reflect. I've spent the whole day trying to make this work.

Edit: Adding current output pic. 数据未传递到模态

Please help me!

As pointed out by @charlietfl, it was a hoisting issue. To use the above code, move var ModalInstanceCtrl = func.. outside the button's ng-click call of $http .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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