user3248761
user3248761

Reputation: 371

Passing data in $mdDialog and use in html template

I am using $mdDialog dialog and want dynamic header in my dialog template. I want to send data in popup template. This is my dialog code.

$scope.showAdvanced = function (ev, Title) {
        $rootScope.tt = Title;
        var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
        $mdDialog.show({
            controller: DialogController,
            templateUrl: 'setting/dialog1.tmpl.html',
            parent: angular.element(document.body),
            targetEvent: ev,
            clickOutsideToClose: true,
            fullscreen: useFullScreen,
            locals: { Title: Title },
        })
        .then(function (answer) {
            $scope.status = 'You said the information was "' + answer + '".';
        }, function () {
            $scope.status = 'You cancelled the dialog.';
        });
        $scope.$watch(function () {
            return $mdMedia('xs') || $mdMedia('sm');
        }, function (wantsFullScreen) {
            $scope.customFullscreen = (wantsFullScreen === true);
        });
    };

My dialog controller is

function DialogController($scope, $mdDialog) {

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

Now i want to use Title in dialog1.tmpl.html template.

Upvotes: 1

Views: 1158

Answers (1)

You should inject Title to your dialog's controller

function DialogController($scope, $mdDialog, Title) {

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

Upvotes: 1

Related Questions