使用 bootstrap 无法在 angularjs 中打开模式窗口

2024-03-03

这是我的 app.js 文件:

const app = angular.module('CurseTransport', [
    'ui.router',
    'ui.bootstrap',
    'ngMessages',
    'raceModule',


])

app.config(['$stateProvider', '$urlRouterProvider', '$qProvider', function($stateProvider, $urlRouterProvider, $qProvider) {
    $qProvider.errorOnUnhandledRejections(false)
    $urlRouterProvider.otherwise('/races')
    $stateProvider
        .state('races', {
            url : '/races',
            templateUrl :'views/races.html',
            controller:'racesController'
        })
          .state('racesInsert', {
            url: '/races/insert',
            onEnter: ['$stateParams', '$state', '$modal',
              function($stateParams, $state, $modal) {
                $modal

                  // handle modal open
                  .open({
                    template: 'views/racesInsert',
                    windowClass : 'show',
                    controller: ['$scope',
                      function($scope) {
                        // handle after clicking Cancel button
                        $scope.cancel = function() {
                          $scope.$dismiss();
                        };
                        // close modal after clicking OK button
                        $scope.ok = function() {
                          $scope.$close(true);
                        };
                      }
                    ]
                  })

                  // change route after modal result
                  .result.then(function() {
                    // change route after clicking OK button
                    $state.transitionTo('races');
                  }, function() {
                    // change route after clicking Cancel button or clicking background
                    $state.transitionTo('races');
                  });

              }
            ]

          });





}])

我对模态窗口的看法:

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

当我单击按钮打开模式窗口时,它不起作用。我的控制台没有错误。我也将其包含在我的脚本中。

我的模态位于不同的 html 文件中。


你读过文档吗?https://angular-ui.github.io/bootstrap/#/modal https://angular-ui.github.io/bootstrap/#/modal

你需要使用templateUrl, not template引用模态模板时,请务必包含文件扩展名:

$modal.open({
  templateUrl: 'views/racesInsert.html',
  windowClass : 'show',
  ...

仅使用template如果您像这样内联定义模板:

$modal.open({
  template: '<div class="modal-header"><h1>Modal Heading</h1></div>...',
  windowClass: 'show',
  ...

如果您使用内联模板作为脚本,则需要使用适当的脚本标记来声明模板。并且,不要包含外部对话框容器:

<script id="racesInsert.html" type="text/ng-template">
  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">Modal Header</h4>
    </div>
    <div class="modal-body">
      <p>Some text in the modal.</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </div>
</script>

$modal.open({
  templateUrl: 'racesInsert.html',
  windowClass : 'show',
  ...

您没有提及您正在使用哪个版本的 Angular UI Bootstrap。当前版本使用$uibModal not $modal作为导入的模块。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 bootstrap 无法在 angularjs 中打开模式窗口 的相关文章

随机推荐