1
 <div class="modal-content">
    <div class="modal-header">
        <h3 class="modal-title">Standard message modal</h3>
    </div>

    <div class="modal-body">

    </div>
    <div class="modal-footer">
        <button class="btn btn-default">Yes</button>
        <button class="btn btn-default">No</button>
    </div>
</div>

我是 angularJS 的新手,我希望在遇到警报语句时打开模式。基本上使用模式来提醒而不是提醒框

4

2 回答 2

0

只需使用 Angular-Strap 之类的东西:http: //mgcrea.github.io/angular-strap/##modals

我不推荐它。但是您可以使用自定义代码覆盖警报:

window.alert = function(msg){ console.log(msg) }; 
alert('foo'); // logs to console
于 2014-08-05T23:28:08.617 回答
0

我不确定您是否可以覆盖浏览器对警报的处理。您至少需要使用注入的工厂来更改(查找和替换)您的警报代码......

这样做的好处是,您可以将 modalFactory 注入您需要从(可能是所有这些)引发模式的任何控制器中,并一致地重用该代码。虽然它没有回答您覆盖 Alert 的问题,但它确实为您提供了一种以编程方式显示模态元素的方法。这是 plunk http://plnkr.co/edit/0QNxUrQ7DH101VrFD0Me?p=preview希望它有所帮助。

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, modalFactory) {
  $scope.name = 'ttt';

  $scope.RunProcess =  function() {
    //error occured
    modalFactory.show($scope);
  }

  $scope.Reset =  function() {
    modalFactory.hide($scope);
  }

});

app.factory('modalFactory', function() {
  return {
    show: function($scope) {
      $scope.showModal = true;
    },
    hide: function($scope) {
      $scope.showModal = true;
    }
  }
});

那么在你看来

 <body ng-controller="MainCtrl">
  <div class="my-modal" ng-show="showModal">
    blahhh
  </div>
    <p>Hello {{name}}!</p>
    <div>
      <button ng-click="RunProcess()">button that runs a controller method and throws alert</button>
    </div>
  </body>
于 2014-08-05T14:43:09.533 回答