简体   繁体   English

UI Bootstrap Modal弹出窗口无法与AngularJS一起使用

[英]UI Bootstrap Modal popup not working correctly with AngularJS

My code is like this 我的代码是这样的

    angular.module('RateRequestApp.controllers', []).controller('ReadOnlyController', [ '$scope', '$modal',
    function($scope, $modal) {
        var data = [];
        data.push("first message");
        this.openReprintModal = function() {
            var modalInstance = $modal.open({
                templateUrl: 'ReprintModal.html',
                controller: 'ModalInstanceCtrl',
                resolve: {
                    items: function() {
                        return data;
                    }
                }
            });
        };
        this.openReprintModal();

    }
]);

angular.module('RateRequestApp.controllers').controller('ModalInstanceCtrl', function($scope, $modalInstance) {

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

  <div id="RateRequestApp" class="content" ng-app='RateRequestApp' ng-controller="ReadOnlyController">
 <script type="text/ng-template" id="ReprintModal.html">
                <div class="modal-header">
                    <h3 class="modal-title">Check this out</h3>
                </div>
                <div class="modal-body">
                    <ul>
                        <li ng-repeat="item in items">
                            <span>{{ item }}</span>
                        </li>
                    </ul>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary" ng-click="ok()">OK</button>
                    <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
                </div>
            </script>
        </div>

All works Okay Except there is no message shown at the body of modal. 所有工作正常,除了模式主体没有显示任何消息。 Apparently everyhting works except ` 显然,除“

<li ng-repeat="item in items">
        <span>{{ item }}</span>
 </li>`

This part is not working.Can any one point out any possible reason. 这部分不起作用。任何人都可以指出任何可能的原因。 Note: I am using this one for model : http://angular-ui.github.io/bootstrap/ 注意:我正在使用这个模型: http : //angular-ui.github.io/bootstrap/

You have to inject items object to your ModalInstanceCtrl like this: 您必须像这样 items对象注入到ModalInstanceCtrl中:

angular.module('RateRequestApp.controllers')
  .controller('ModalInstanceCtrl', function($scope, $modalInstance, items) {
    $scope.items = items;
    ...
});

And then you are able to access it in your view just like you have it now 然后您就可以像现在一样在视图中访问它

<li ng-repeat="item in items">
    <span>{{ item }}</span>
</li>

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

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