【发布时间】:2016-09-30 10:52:18
【问题描述】:
我正在尝试编写一个功能,如果我们传递范围和模板,它应该在 jQuery UI 对话框中显示给定模板,其中包含给定范围内的所有工作绑定。
代码如下:
HTML
<div id="mainDiv" ng-controller="myCtrl">
<input type="button" value="show dialog" ng-click="showTemplateDialog()" />
</div>
<script type="text/ng-template" id="dialogTemplate">
<div>
This is template div.
<span>Message: </span>
<p>{{message}}</p>
</div>
</script>
JS
var app = angular.module('myApp', []).controller('myCtrl', function($scope, $compile) {
$scope.showTemplateDialog = function() {
alert("hi")
var newScope = $scope.$new();
newScope.message = "This is some message";
$scope.showDialog(newScope, "dialogTemplate")
};
$scope.showDialog = function(dialogScope, template) {
var div = $("<div style='' id='dialog' title='Test Dialog' ng-include=\"'" + template + "'\"></div>");
$compile(div)(dialogScope);
$("#mainDiv").append(div);
div.dialog();
}
})
问题是当我调用div.dialog() 时,它会在jquery-ui.min.js 中引发以下错误
Unhandled exception at line 9, column 26027 in http://localhost/TestApp/scripts/jquery-ui.min.js
0x800a138f - JavaScript runtime error: Unable to get property 'display' of undefined or null reference
请提出一些解决此错误的方法。或者建议使用 angularjs 在 jQuery 对话框中显示和 html/模板的其他方式。
【问题讨论】:
-
顺便说一句,您的输入元素有 HTML 语法错误。
标签: angularjs jquery-ui dialog