0

I am trying to develop a dynamic dialog box. The text is coming on a $http.get response. but somehow it is not working. A little help will be really appreciated. I am using node.js and angular.

angular.module('rugCoPro')

.controller('DashboardController', [
    '$scope',
     'Session',
     '$location',
     'ObjectUtils',
     '$http',
     '$state',
     '$stateParams',
     '$mdDialog',
     function(
        $scope,
        session,
        $location,
        ObjectUtils,
        $http,
        $state,
        $stateParams,
        $mdDialog
    ){


    if(!session.isAuthenticated()){
        session.logout();
    }

    $http.get("api/models/department").success(function(response, status, headers){
        $scope.app_modes = response;
    });

    $scope.load = function(ev) {
        $mdDialog.show({
          controller: DialogController,
          template:
           '<md-dialog aria-label="List dialog">' +
           '  <md-dialog-content>'+
           '    <md-list>'+
           '      <md-list-item ng-repeat="item in items">'+
           '       <p>{{item.name}}</p>' +
           '      </md-list-item>'+
           '    </md-list>'+
           '  </md-dialog-content>' +
           '</md-dialog>',
          parent: angular.element(document.body),
          targetEvent: ev,
          clickOutsideToClose: true,
          locals: {
           items: $scope.app_modes
         },
        });
      };

    function DialogController($scope, $mdDialog) {
        $scope.items = $scope.app_modes;
        $scope.hide = function() {
          $mdDialog.hide();
        };

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

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

Template ejs code

<md-content ng-controller="DashboardController as ctrl" class="md-padding" ng-init='load()'>

    <div layout="row" layout-align="start center"> 
        <h6 class="md-headline">{{"Turco Persian Rug Co."| uppercase}}</h6>
    </div>

</md-content>

I am trying to display the 'app_modes' list on the md-dialog.

jatinder bhola
  • 385
  • 1
  • 7
  • 23
  • 1
    *"it is not working"* tells us next to nothing that doesn't require us to ask you a lot of questions. Take a few minutes to review [ask] then update question with a proper technical problem statement and troubleshooting details. – charlietfl Oct 04 '16 at 18:51
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Heretic Monkey Oct 04 '16 at 19:41

1 Answers1

0

The simplest solution to your problem is:

$http.get("api/models/department").success(function(response, status, headers){
        $scope.app_modes = response;
        $scope.load();
    });

And you loose the ng-init="load()". It will first load the data, then show the dialog.

Stefa
  • 656
  • 5
  • 13