【问题标题】:Close icon doesn't work on Bootstrap Modal using AngularJs关闭图标在使用 AngularJs 的引导模式上不起作用
【发布时间】:2015-01-12 09:18:35
【问题描述】:

我正在使用 Twitter-Bootstrap 模式。我在模态标题上设置了一个关闭图标。我需要激活这个图标来关闭模态框。

<div class="modal-content json-modal-body" id="full-width" ng-controller="projectdetailsController" close="CloseModal()"> 
  <div class="modal-header modal-header-confirm"> 
    <h4 class="modal-title ng-binding"> 
      <span class="glyphicon glyphicon-indent-left"></span>{{modalOptions.headerText}} 
      <a type="button" title="Close" data-dismiss="modal"><i ng-click="CloseModal()"    class="glyphicon glyphicon-remove icon-arrow-right pull-right"></i></a> 
    </h4> 
  </div>
  <div class="modal-body"> 
    <pre class="Modal-pre" ng-bind-html="modalOptions.bodyText"></pre> 
  </div> 
</div>

控制器:

var modalInstance=$scope.showJSON = function(){
  var modalOptions = {
    headerText: ' JSON Schema View',
    bodyText: 'jsonSchema'
  };
  var modalDefaults = {
    templateUrl: 'app/partials/jsonModal.html'
  };        
  modalService.showModal(modalDefaults, modalOptions).then(function (result) {

  });
}
$scope.CloseModal = function () {
  $modalInstance.close(); 
}

我正在使用ng-click="CloseModal()" 关闭模式。我还在父 div 上声明了close="CloseModal()"。我该如何解决这个问题?

我有一个用于此模式的 AngularJs 控制器。我可以使用控制器吗?

【问题讨论】:

  • 你在做什么?这是你的控制器吗?
  • 要显示模态,我使用控制器.. 当单击关闭图标时,我想关闭模态。
  • 我已经发布了示例。试试这个。

标签: javascript angularjs twitter-bootstrap bootstrap-modal


【解决方案1】:

你必须在你的控制器中声明函数 CloseModal()

如果你使用angular-ui bootstrap,它应该是这样的:

 ['$scope', '$modalInstance', function($scope, $modalInstance){ 

...

$scope.CloseModal = function () {
   $modalInstance.close(); 
}

【讨论】:

  • $modalInstance 未定义
  • 未知提供者:$modalInstanceProvider
  • 你使用angular-ui bootstrap吗
  • 你应该使用 angular-ui bootstrap,因为它与 angular 很好地集成了
【解决方案2】:

按照以下步骤操作:

var app =  angular.module('myApp',['ui.bootstrap']);

//模态控制器

 app.controller('modalCtrl',['$scope','$modalInstance', function ($scope,$modalInstance) {
        'use strict';
    $scope.cancel = function () {
        $modalInstance.dismiss();
    };

第二个控制器:

app.controller('Ctrl',['$scope','$modal', function ($scope,$modal) {

   $scope.openModal= function () {

      $modal.open({
                    backdrop: true,
                    keyboard: false,
                    backdropClick: false,
                    templateUrl: "path of your modal HTML",
                    dialogClass: "modal-content",
                    controller: 'modalCtrl',
                });
    }

【讨论】:

  • 但是我使用了一个控制器 .. ng-controller="projectdetailsController" 并且我使用了 Twitter-Bootstrap Modal。
  • 你的模型是否正在打开..?
  • 是的...当我按下“Esc”键时,它正在关闭。
  • 试试这种方式..我不明白你在做什么。所以如果可以的话,请关注t,网上还有很多其他例子。谷歌它..
  • 您是否像我一样在控制器中包含了 $modalInstance ......?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
  • 2018-06-13
  • 2020-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多