ReferenceError:未定义ModalInstanceCtrl

时间:2016-03-14 18:14:24

标签: javascript angularjs

我正在尝试在angularJS中创建一个模态。一切似乎都没问题,但是当我启动我的应用程序时,我收到了这个错误:

ReferenceError: ModalInstanceCtrl is not defined

这是控制器。请问可能出错

<div ng-controller="ModalDemoCtrl">

    <div inner-html-bind inner-html="modal_html_template" class="hidden">
        <div class="modal-header">
            <h3>I'm a modal!</h3>
        </div>
        <div class="modal-body">
            <ul>
                <li ng-repeat="item in items">
                    <a ng-click="selected.item = item">{{ item }}</a>
                </li>
            </ul>
            Selected: <b>{{ selected.item }}</b>
        </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>
    </div>

    <button class="btn" ng-click="open()">Open me!</button>
    <div ng-show="selected">Selection from a modal: {{ selected }}</div>
</div>

这是插件演示 https://plnkr.co/edit/337WvYpo38QtJjIYtLhK?p=preview

1 个答案:

答案 0 :(得分:0)

您应该在单引号内写ModalInstanceCtrl

var modalInstance = $modal.open({
      template: $scope.modal_html_template,
      controller: 'ModalInstanceCtrl',
      resolve: {
        items: function() {
          return $scope.items;
        }
      }
    });

Plunker