Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
访问$mdDialog控制器-AngularJs 1.X.X中的$scope变量时出现问题_Angularjs_Angularjs Scope_Angular Material_Angular Promise_Md Select - Fatal编程技术网

访问$mdDialog控制器-AngularJs 1.X.X中的$scope变量时出现问题

访问$mdDialog控制器-AngularJs 1.X.X中的$scope变量时出现问题,angularjs,angularjs-scope,angular-material,angular-promise,md-select,Angularjs,Angularjs Scope,Angular Material,Angular Promise,Md Select,我使用$mdDialog,并指定了另一个js文件中存在的控制器 父Js控制器: $scope.AddDesignationPrompt = function(ev) { $mdDialog.show({ controller: 'AddDesignationPromptController', templateUrl: './Employee/Views/AddDesignation.tmpl.html', parent: angular.

我使用$mdDialog,并指定了另一个js文件中存在的控制器

父Js控制器:

$scope.AddDesignationPrompt = function(ev) {
    $mdDialog.show({
        controller: 'AddDesignationPromptController',
        templateUrl: './Employee/Views/AddDesignation.tmpl.html',
        parent: angular.element(document.body),
        targetEvent: ev,
        clickOutsideToClose:true,
        fullscreen: true // Only for -xs, -sm breakpoints.
    })
    .then(function(answer) {
        $scope.GetPriliminaryData();
    }, function() {
        $scope.status = 'You cancelled the dialog.';
    });
};
app.controller('AddDesignationPromptController', function ($scope, $rootScope, $mdDialog, $window, HTTPService) {
    $scope.loadUpData = {
            State: [],
            Department: [],
            Designation: []
      };

      HTTPService.getPriliminaryRegData().then(function (result) {
            if ((result != undefined) && (result != null)) {

                $scope.loadUpData = {
                    State: [],
                    Department: result.Result.Department,
                    Designation: []
                };

                console.log("Inside");
                console.log($scope.loadUpData);

            }
        });

    console.log("Outside");
    console.log($scope.loadUpData);

    $scope.hide = function() {
      $mdDialog.hide();
    };

    $scope.cancel = function() {
      $mdDialog.cancel();
    };

    $scope.answer = function(answer) {
      $mdDialog.hide(answer);
    };
});
对话框控制器:

$scope.AddDesignationPrompt = function(ev) {
    $mdDialog.show({
        controller: 'AddDesignationPromptController',
        templateUrl: './Employee/Views/AddDesignation.tmpl.html',
        parent: angular.element(document.body),
        targetEvent: ev,
        clickOutsideToClose:true,
        fullscreen: true // Only for -xs, -sm breakpoints.
    })
    .then(function(answer) {
        $scope.GetPriliminaryData();
    }, function() {
        $scope.status = 'You cancelled the dialog.';
    });
};
app.controller('AddDesignationPromptController', function ($scope, $rootScope, $mdDialog, $window, HTTPService) {
    $scope.loadUpData = {
            State: [],
            Department: [],
            Designation: []
      };

      HTTPService.getPriliminaryRegData().then(function (result) {
            if ((result != undefined) && (result != null)) {

                $scope.loadUpData = {
                    State: [],
                    Department: result.Result.Department,
                    Designation: []
                };

                console.log("Inside");
                console.log($scope.loadUpData);

            }
        });

    console.log("Outside");
    console.log($scope.loadUpData);

    $scope.hide = function() {
      $mdDialog.hide();
    };

    $scope.cancel = function() {
      $mdDialog.cancel();
    };

    $scope.answer = function(answer) {
      $mdDialog.hide(answer);
    };
});
视图:


新部门
进入新部门

{{key.Name} 无用 有用的


它位于控制器级别,但不在md select中加载。请帮助我如何在视图中加载集合。

您正在循环加载更新a.Designation,它始终设置为空数组
[]
,因此不会显示任何内容。在您的
HTTPService
promise resolve中填充的唯一数据是
loadupdatea.Department
,但您从不在HTML中打印它

如果结果中有
名称
,则填充它,例如:

HTTPService.getPriliminaryRegData().then(function (result) {
  if (result && result.Result) {

    $scope.loadUpData = {
      State: [],
      Department: result.Result.Department,
      Designation: result.Result.Designation
    };

    console.log("Inside");
    console.log($scope.loadUpData);

  }
});

进入控制器级别而不加载md select是什么意思?在对话框中,我有一个
md select
。集合未加载到
md select
中。此外,请参考此快照@Sajeetharan,仔细查看我的最后一条评论…可能与@georgeawg重复-谢谢,我会检查。。。