• 页面modal服务


    /**
    *
    *
    * 初始化:
    * var oneModal = modalSvc.createModal(templateUrl, controller, size);
    * size可以是:lg或sm
    *
    * 打开modal并传递数据
    * oneModal.show(params);
    * 通过参数params可以向modal中传递数据
    * <span>{{params.title}}</span>
    *
    *
    * 通过完成事件获得结果
    * function onModalComplete(result) {
    * }
    * oneModal.show(params).then(onModalComplete);
    * 其中result 就是modal关闭时的结果,也是hide函数传回的值: hide(result)
    * 如果通过其他方式关闭modal,也会调用onModalComplete,但result为undefined
    *
    *
    * 关闭modal
    * oneModal.hide(result)
    * result作为modal的结果,传回调用者
    *
    *
    * 在模板中关闭modal
    * <button ng-click="hide(true)">OK</button>
    * <button ng-click="hide()">Cancel</button>
    *
    */
    angular.module('nCloud.bootstrapModalSvc', ['ui.bootstrap'])
    .factory('bootstrapModalSvc', [
    '$q', '$rootScope', '$uibModal'
    , function ($q, $rootScope, $uibModal) {
    function createModal(templateURL, controller, size) {

    var modalService = {
    scope: undefined,
    modalWindow: undefined,

    show: function (params) {
    this.scope = $rootScope.$new();
    this.scope.params = params;
    this.scope.hide = function (result) {
    this.$close(result);
    };

    this.modalWindow = $uibModal.open({
    templateUrl: templateURL,
    scope: this.scope,
    controller: controller,
    size: size
    });

    var q = $q.defer();
    this.modalWindow.result.then(
    function (result) {
    q.resolve(result);
    },
    function (reason) {
    q.resolve();
    }
    );
    return q.promise;
    },

    hide: function (result) {
    if (this.modalWindow) {
    this.modalWindow.close(result);
    }
    }
    };

    return modalService;
    }

    return {createModal: createModal};
    }
    ])
    ;

    如果未使用uiBootstrap,将$uibModal换为$modal

  • 相关阅读:
    VS2010的新特性:3.新要害词 Dynamic
    VS2010的新特性:1.可选参数
    VS2010的新特性:4.简化了对 Office API 对象的访问
    VS2010的新特性:2.命实参数
    Not beside my body,but inside my heart!
    Tears...
    首乘“子弹头”列车
    What doesn't kill me makes me stronger!
    HongKong Business Trip
    胃部不适,原来好辛苦!
  • 原文地址:https://www.cnblogs.com/maoyazhi/p/5279407.html
Copyright © 2020-2023  润新知