使用带有uibmodal的呈现属性会抛出错误

时间:2016-12-09 18:14:12

标签: javascript angularjs

在modal.results上使用我的模态角度抛出错误时,说模态是未定义的。我提前做错了什么,谢谢!!

我使用querySelector来获取模态对话框,这样我就可以动态设置属性,但效果很好..但不能从选择中获得结果

function showMyPopover(p) {           
        var modal = $uibModal.open({
            templateUrl: '/app/templates/modals/customPopoverModal.html',
            controller: 'customPopoverController as vm',
            size: 'sm',
            animation: true,
            windowClass: 'level-modal',
            windowTopClass: 'ng-animate',
            resolve: {                   
               results: function () {
                    return vm.results;
               }
            }                
        }).rendered.then(function () {
            // Grab target element
            //var element = document.querySelector('#pid' + p),
            var element = $('#pid' + p);
            var ePosition = element.offset();
            var mLeft = 25;
            var mTop = 25;
            popModal = document.querySelector('.modal-dialog');

            // Set style 
            popModal.style.margin = 0;
            popModal.style.top = 0;
            popModal.style.left = 0;
            popModal.style.backgroundColor = "green";
            var oTop = ePosition.top;
            var oLeft = ePosition.left;
            popModal.style.top = oTop + mTop + "px";
            popModal.style.left = oLeft + mLeft  + "px";
        });
        modal.result.then(function (reply) {
            vm.action = reply.choice;                               
        });
    }

1 个答案:

答案 0 :(得分:0)

在google上进行了几次搜索后...我发现了一篇提到$ uibModalInstance的帖子,经过几次尝试后我终于得到了我的自定义对话框,允许我动态渲染和定位它并返回错误结果。

我从上面的代码中删除了.rendered并将其添加到此处...

注意:p = 17只是一个测试值...所以它知道在哪里设置模态。

  function activate() {          
        $('#one').focus();
        $uibModalInstance.rendered.then(function () {
            doPositioning();
        });
    }

    function doPositioning() {
        var p = 17;
        var element = $('#pid' + p);
        var ePosition = element.offset();
        var mLeft = 25;
        var mTop = 25;
        var popModal = $('.modal-dialog');
        var oTop = ePosition.top + mTop;
        var oLeft = ePosition.left + mLeft;

        // Set style
        popModal.css("margin","0");
        popModal.css("top", oTop + "px");
        popModal.css("left", oLeft + "px");          
    }