AngularJS弹出框 $modal的使用

//HTML:注意在Chrome浏览器中会给input添加默认样式,影响到打钩的框出不来,主要是position和影响透明度的opacity
<script type="text/ng-template" id="noticeListModal.html">
    <div class="modal-header">
        <h3 class="modal-title">发送通知</h3>
    </div>
    <div class="modal-body">
        <form>
            <div style="float:right">
                <label style="margin-right:15px">
                    <input type="checkbox" ng-model="isHouseOwnerChecked" style="position:static;opacity: 0.5" value="屋主" checked>
                    屋主</label>
                <label style="margin-right:15px">
                    <input type="checkbox" ng-model="isHirerChecked" style="position:static;opacity: 0.5" value="租户" checked>
                    租户</label>
            </div>
            <div>
                <label style="margin-bottom: 10px">
                    标题:<input type="text" ng-model="noticeTitle" style="width: 350px;">
                </label>
                <textarea cols="91" rows="8" name="contactus" ng-model="notice">{{notice}}</textarea>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-blue" ng-click="ok()">确定</button>
        <button class="btn btn-warning" ng-click="cancel()">取消</button>
    </div>
</script>

//JS:showEdit是点击button的事件,写在method中;

showEdit:function (trueOrfalse) {
            var modalInstance = $modal.open({
                windowClass: '',
                templateUrl: 'noticeListModal.html',
                controller: 'ModalInstanceCtrl',
                resolve: {
                }
            });
            modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数
                console.log('modal is opened');
            });
            modalInstance.result.then(function (ret) {//模态窗口关闭之后回传参数
$modalInstance.close($scope.selected);
                 console.log(ret); 
             }, function (reason) { 
                 console.log(reason); 
          }); 
       }


//模态窗口的controller
app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, toaster) {
    $scope.notice = '';
    $scope.noticeTitle = '';
    $scope.isHouseOwnerChecked = 0;
    $scope.isHirerChecked = 0;

    $scope.ok = function() {
        $scope.isHouseOwnerChecked = $scope.isHouseOwnerChecked?1:0;
        $scope.isHirerChecked = $scope.isHirerChecked?1:0;
        if(!$scope.notice || !$scope.noticeTitle) {
            toaster.pop("error", "请添加通知内容");
            return
        }
        if(!$scope.isHouseOwnerChecked && !$scope.isHirerChecked) {
            toaster.pop("error", "请选择发送角色");
            return
        }

        $.ajax({
                url: "/rest/sysNotice/test",
                data:{
                    isNoticeHouseOwner:$scope.isHouseOwnerChecked,
                    isNoticeHirer:$scope.isHirerChecked,
                    memo:$scope.notice,
                    title:$scope.noticeTitle
                },
                success: function (resp) {
                    if(resp.success) {
                        toaster.pop("success", "发送成功", resp.message);
                    }else{
                        toaster.pop("error", "发送通知", resp.message);
                    }
                }
            });
        $modalInstance.close();

    };
    $scope.cancel = function() {
        $modalInstance.dismiss('cancel');
    };
});

详细的$modal属性和方法可以参考这里:

https://blog.csdn.net/CSDN_lihe/article/details/49633481

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一望损莓苔

一毛钱的动力~yeah~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值