【发布时间】:2014-04-25 15:10:23
【问题描述】:
我正在尝试从角度控制器调用模态对话框。这个例子非常简单,而且非常简单。我有诸如
之类的代码$modal.open({
template: '<div class="modal-body">Choose current project<button class="btn btn-primary" ng-click="ok()">OK</button> <button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>',
controller: ModalChooseProjectCtrl
});
控制函数声明为
var ModalChooseProjectCtrl = function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close($scope.chosenProject);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
它是从属于div的控制器函数中调用的,其中包含引导程序的导航栏。
问题:当我调用具有 $modal.open 调用的函数时,会显示错误
Error: [$compile:tplrt] Template for directive 'modalBackdrop' must have exactly one root element. template/modal/backdrop.html
http://errors.angularjs.org/1.2.15-build.2378+sha.9335378/$compile/tplrt?p0=modalBackdrop&p1=template%2Fmodal%2Fbackdrop.html
Error: [$compile:tplrt] Template for directive 'modalWindow' must have exactly one root element. template/modal/window.html
http://errors.angularjs.org/1.2.15-build.2378+sha.9335378/$compile/tplrt?p0=modalWindow&p1=template%2Fmodal%2Fwindow.html
这些错误表明模板,可以说,必须被包装在一个 html 根元素中,这显然是模板。 此外,调用后我看到代码中出现了以下元素
<div modal-backdrop="" class="ng-scope"></div>
<div modal-window="" index="0" animate="animate" class="ng-scope"></div>
如果我进一步点击,更多的模态窗口会出现在代码中。但是屏幕只是跳跃,没有任何反应,我没有得到我的模态对话框。而在 Plunker 中,对话框的调用代码显示它很好(http://plnkr.co/edit/VJ1Kick7QWE3X0bL6gtw,但它只是基本的调用例程。)
【问题讨论】:
-
因为它适用于 Plunker;这可能是 AngularJS、BootStrap 和 UI Bootstrap 版本不兼容的问题吗?
-
我使用凉亭安装...我似乎有 angular 1.2 和 ng-bootstrap 0.10,来自 bootstrap 3.1.1 的 css
-
好像没有html2js模板,你检查了吗?
标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap