angularjs+bootstrap modal的使用

在AngularJS中主要使用bootstrap-modal使用弹窗效果。

安装bootsrap-modal插件:

bower install bootstrap-modal --save

基本组件引用:

    <link rel="stylesheet" href="bower_components/bootstrap-modal/css/bootstrap-modal.css" />
    <script src="bower_components/bootstrap-modal/js/bootstrap-modal.js"></script>
    <script src="bower_components/bootstrap-modal/js/bootstrap-modalmanager.js"></script>

html开发:

      <div class="modal fade in" id="addNatgwModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-sm">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
              <h4 class="modal-title" id="myModalLabel">添加NAT网关</h4>
            </div>
            <div class="modal-body form-group">
              <div class="row">
                <label class="control-label col-sm-4" for="natgwAddIp">ip地址:</label>
                <div class="col-sm-8">
                  <input type="text" class="form-control" id="natgwAddIp">
                </div>
              </div>
              <div class="row">
                <label class="control-label col-sm-4" for="natgwAddPort">端口号:</label>
                <div class="col-sm-8">
                  <input type="text" class="form-control" id="natgwAddPort">
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="button" class="btn btn-primary" id="addNatgwModalBtn" ng-click="addNatgw()">确定</button>
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal -->
      </div>

上述创建了一个modal,其中有两个label,两个input和两个button

js开发:

定制modal中相关动作实现,这时候就需要在controller中添加部分代码:

    $('#addNatgwModalBtn').on('click', function () {
      var ipAddr = $('#natgwAddIp').val();
      var port = $('#natgwPort').val();
      var data = {'ip': ipAddr, 'agent_port': port};

      $http({
        url: 'http://127.0.0.1:8000/api/v1/natgw',
        method: 'post',
        data: data
      }).then(
        function successCallback(response) {
          console.log('response is:', response);
          $('#addNatgwModal').modal('hide');
          $('#natgwTable').bootstrapTable('refresh', {silent: true});
        },
        function errorCallback(error) {
          console.log('response is:', error);
        }
      )
    });

结果呈现:

modal_page.png

参考资料:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,969评论 19 139
  • 原文出处 http://blog.poetries.top/2016/11/19/bootstrap-review...
    前端进阶之旅阅读 7,129评论 0 42
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,247评论 4 61
  • Bootstrap是什么? 一套易用、优雅、灵活、可扩展的前端工具集--BootStrap。GitHub上介绍 的...
    凛0_0阅读 10,925评论 3 184
  • 我的人生过往,一切的不幸或幸福我都可以统统接纳,但却留下一个遗憾无法启齿!这是一份无法继续的缘分,不是我...
    语默若语阅读 492评论 0 0