Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
作为弹出对话框加载模板后未加载angularjs范围_Angularjs - Fatal编程技术网

作为弹出对话框加载模板后未加载angularjs范围

作为弹出对话框加载模板后未加载angularjs范围,angularjs,Angularjs,点击一个按钮,我想打开一个模式对话框窗口,并将template.html页面加载到弹出窗口中。在我的模板中,我有一个下拉列表,在我从Angularjs工厂服务WCF服务调用接收数据的情况下,它需要与数据库中的数据绑定 对话框窗口打开后未加载下拉列表 在下面找到我的代码:打开弹出对话框的第一个控制器: app.controller('MyFirstController', function ($scope, $compile) { $scope.showTrackingPopup = f

点击一个按钮,我想打开一个模式对话框窗口,并将template.html页面加载到弹出窗口中。在我的模板中,我有一个下拉列表,在我从Angularjs工厂服务WCF服务调用接收数据的情况下,它需要与数据库中的数据绑定

对话框窗口打开后未加载下拉列表

在下面找到我的代码:打开弹出对话框的第一个控制器:

app.controller('MyFirstController', function ($scope, $compile) {

    $scope.showTrackingPopup = function () {
        var Id = 111;        
        var popupTpl = document.createElement("div");
        popupTpl.setAttribute("id", "TestDialog");
        popupTpl.setAttribute("ng-app", "MyApp");
        popupTpl.setAttribute("ng-include", "'app/templates/Test-template.html'");
        popupTpl.setAttribute("ng-controller", "MySecondController");
        popupTpl.setAttribute("ng-init", "InitData(Id)");
        var popupScope = $scope.$new();
        popupScope.someValue = Math.random();
        var popupLinker = $compile(popupTpl);
        var popupElement = popupLinker(popupScope);

        var dialog = $('<div/>').html(popupElement);

        dialog.dialog({
            modal: true,
            width: 'auto',
            height: 'auto',
            draggable: true,
            resizable: false,
            position: { my: "left", at: "center", of: window },
            close: function (event, ui) {
                $('body').find('#TestDialog ').remove();
                popupScope.$destroy();
            }
        });      
        return false;
      }
}); 

如何等待第二个控制器,直到数据从工厂服务返回,然后自动加载下拉列表?请帮忙

如果不知道FactService.GetDropdownData返回的是什么,我无法确定,但在正常情况下,它应该是一个$http承诺。在这种情况下,当这个承诺实现时,您必须加载下拉数据

例如:

FactService.GetDropdownData(Id).
.success(function(data){
    // your $http promise was fullfiled successfuly and you have your data
    $scope.DropDownData = data;
}
.error(function(err){ /* handler your error here */});

此外,我不太确定Id值是否以您的方式在ng init中正确传递。它也被认为是在控制器中操纵DOM的一个糟糕的实践,而不是考虑创建一个指令。如果你想要更容易弹出框,你可能想考虑模块

谢谢你的回复。角度ui引导css正在弄乱我的网站。从上面的控制器可以了解如何在第一个控制器中添加scope dropdowndata,以及如何在ng repeat in模板中添加watcher。在第二个控制器中,是否将摘要应用于更新视图?我在这里面临着约束问题。这种方法正确吗?
FactService.GetDropdownData(Id).
.success(function(data){
    // your $http promise was fullfiled successfuly and you have your data
    $scope.DropDownData = data;
}
.error(function(err){ /* handler your error here */});