将数据绑定到模态

时间:2016-02-22 06:01:53

标签: angularjs angular-ui

我试图通过函数传递一些数据来显示模态,但是通常的绑定方法不起作用,我希望有人能指出我正确的方向。

  $scope.openModal = function (obj) {


    //$scope.data = {type: obj.type, descriptions: obj.description, isDone: obj.isDone, createDate: obj.createDate, priority: obj.priority};

    $scope.data = obj;

    console.log($scope.data);

    var modalInstance = $uibModal.open({
      animation: $scope.animationsEnabled,
      templateUrl: 'modalTemplate.html',
      controller: 'View1Ctrl',
      resolve: {
        data: function () {
          return $scope.data;
        }
      }
    });
  }

模板

<!-- MODAL -->


<div>
<div ng-controller="View1Ctrl">
<script type="text/ng-template" id="modalTemplate.html">
        <div class="modal-header">
            <h3 class="modal-title">Item Details</h3>
        </div>
        <div class="modal-body">
            <ul>
                <li>Type: <span ng-model="data.type"></span></li>
                <li>Description: <span ng-model="data.description"></span></li>
                <li>Date: <span ng-model="data.createDate"></span></li>
                <li>Priority: <span ng-model="data.priority"></span></li>
                <li>Finished: <span ng-model="data.isDone"></span></li>
            </ul>
        </div>
        <div class="modal-footer">
        <button class="btn btn-primary" ng-click="$close()">OK</button>
        </div>
    </script>
</div>

还尝试了{{data.type}}等和ng-bind。我现在填充了$ scope.data,因为它在控制台中显示的很多。

2 个答案:

答案 0 :(得分:1)

您应该将data(解析对象)注入模态控制器,然后将其添加到$ scope对象。

答案 1 :(得分:1)

您应该从模板中删除ng-controller =“View1Ctrl”。