Jquery对话框未使用Angular范围填充

时间:2015-07-21 13:03:45

标签: javascript angularjs jquery-dialog

第一次启动对话框时,以下代码似乎不起作用。

        $scope.ke_location_channel_summary = function (region_id, region) {

        $scope.region_data = $scope.location_channel_data[region_id];

            killed_enquiries_services.open_dialog('popup', region);
            $('#popup').html($('#location_channel_summary').html());

    };

但它适用于以下更改

        $scope.ke_location_channel_summary = function (region_id, region) {

        $scope.region_data = $scope.location_channel_data[region_id];

        window.setTimeout(function () {
            killed_enquiries_services.open_dialog('popup', region);
            $('#popup').html($('#location_channel_summary').html());
        }, 0);
    };

代码的HTML方面是

<div id="location_channel_summary" style="display: none">
<table class="standardTable">
    <tr>
        <th class="left-col-heading">Channel</th>
        <th class="center">Qty</th>
        <th class="center">Nights</th>
        <th class="center">Value</th>
        <th class="center">Avg Value</th>
        <th class="center">ADR</th>
    </tr>
    <tr ng-repeat="ctype in contacttypes | orderBy:['sort_order']">
        <td style="width:25%;" class="left-col-td">{{ctype.name}}</td>
        <td ng-repeat="column in columns" class="center">{{region_data[ctype.id][column]}}</td>

    </tr>
</table>

我试图在Jquery对话框上显示div内容。返回的表格为空白内容而没有setTimeOut。为什么会这样?

2 个答案:

答案 0 :(得分:1)

这可能是因为AngularJS观察者是异步的,需要一些时间来解析{{ctype.name}}{{region_data[ctype.id][column]}}表达式。

答案 1 :(得分:1)

你永远不应该尝试在角度内处理Jquery。我建议通过copy-initialization模块构建Dialog。

你正面临着这种麻烦,因为有些人不会做任何事情&#34;所有事情&#34;立刻。它必须运行多个摘要来渲染最终页面......但是Jquery对它没有任何线索,并在角度完成生成页面之前启动它的功能。

$('#popup').html($('#location_channel_summary').html());

这是在角度插入此部分之前发生的

<tr ng-repeat="ctype in contacttypes | orderBy:['sort_order']">
    <td style="width:25%;" class="left-col-td">{{ctype.name}}</td>
    <td ng-repeat="column in columns" class="center">{{region_data[ctype.id][column]}}</td>

</tr>

对于第一次摘要的ng-repeat,HTML可能是空白的,因此您在没有此部分的情况下添加弹出窗口。然后角度解释它并生成它。但是您已经复制了未完全生成的HTML。