ui-bootstrap-modal with ui-bootstrap-tpls-0.13 and bootstrap 3.3.2,angular 1.3.14 not working

时间:2015-06-25 16:34:16

标签: css angularjs twitter-bootstrap angular-ui-bootstrap angular-formly

正如标题中所提到的,模态没有显示出来。 表单的内容通过形式加载,模板的内容似乎加载,但它只显示模式非常薄,覆盖而不是内容。

我有一个主控制器,我有:

$scope.add = function(){
        $modal.open({
            templateUrl: 'app/js/templates/popupAddCarForm.html',
            controller: 'FormsController',
            controllerAs: 'vm',
            backdrop: 'static',
            resolve: {
                formData: function(){
                    return {
                        fields: getFormFields(),
                        model: {}
                    }
                }
            }
        });
    };

我的HTML就像这样:

<script type="text/ng-template" id="popupAddCarForm">
<div class="modal">
    <div class="modal-dialog">
        <div class="modal-header">
            <h3 class="modal-title">Adauga masina</h3>
        </div>
        <div class="modal-body">
            <form name="vm.addCarForm">
                <formly-form model="vm.formData.model" fields="vm.formData.fields">
                </formly-form>
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn btn-default" type="submit" >Adauga</button>
        </div>
    </div>
</div>

我的表单控制器是这样的:

davidintercar.controller('FormsController',
    function($modalInstance, formData) {
        var vm = this;
        //debugger;

        vm.formData = formData;
        vm.originalFields = angular.copy(vm.formData.fields);

    }
);

结果如下:

The modal is in the red square

LATER EDIT:

为了摆脱其他疑惑,以下是演示中的代码:

app.controller('ModalInstanceCtrl', function ($modalInstance, formData) {
var vm = this;
debugger;

// function assignment
vm.ok = ok;
vm.cancel = cancel;

// variable assignment
vm.formData = formData;
vm.originalFields = angular.copy(vm.formData.fields);

// function definition
function ok() {
  $modalInstance.close(vm.formData.model);
}

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

});

链接:angular-formly.com /#/ example / integrations / ui-bootstrap-modal

稍后,后期编辑:

Plunker:http://plnkr.co/edit/8wgL4t2oXsFFeLBKGGW8?p=preview

文件夹结构:

--app
----js
------controller
------services
------templates
------view
----app.js
intex.html

我的popupAddCarForm.html位于模板目录中,但正如您在plunker中看到的那样,它不会呈现我加载的内容,即使在同一目录中也是如此,但它是一个单独的模板文件。

1 个答案:

答案 0 :(得分:2)

模态模板不需要模态和模态对话层 - 它们将由bootstrap生成。

<script type="text/ng-template" id="popupAddCarForm.html">
    <div class="modal-header">test
        <h3 class="modal-title">Adauga masina</h3>
    </div>
    <div class="modal-body">
        <form name="vm.addCarForm">
            <formly-form model="vm.formData.model" fields="vm.formData.fields">
            </formly-form>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn btn-default" type="submit" >Adauga</button>
    </div>
</script>