1

I am trying to add a second input to an angular material dialog, but I am not sure if it is possible. I tried to add the Test2 placeholder but didn't work. Thank you for the help in advance.

 $scope.showPrompt = function (ev) {
    $scope.statusTopic = '';
    var confirm = $mdDialog.prompt()
      .title('Test?')
      .placeholder('Test1')
      //.placeholder('Test2')
      .targetEvent(ev)
      .ok('Okay!')
      .cancel('Cancel');
2
  • You would have to use a Custom Dialog.
    – camden_kid
    Nov 7, 2016 at 14:51
  • Thank you. I am using custom dialog. Could you point me to the right direction/ tutorial/example.
    – user6934713
    Nov 7, 2016 at 15:58

1 Answer 1

0

Here's an example using Custom Dialog - CodePen

Markup

<div ng-controller="MyController as vm" ng-cloak="" ng-app="app">
  <md-button class="md-primary md-raised" ng-click="vm.open($event)">
    Custom Dialog
  </md-button>
  <div ng-if="vm.showText" layout="column">
    {{vm.placeholder1}}
    <br>
    {{vm.placeholder2}}
  </div>

  <script type="text/ng-template" id="test.html">
    <md-dialog aria-label="Test">
        <div layout-padding layout="column">
        <md-input-container>
            <label>Placeholder 1</label>
          <input ng-model="vm.placeholder1">
        </md-input-container>
        <md-input-container>
            <label>Placeholder 2</label>
          <input ng-model="vm.placeholder2">
        </md-input-container>
        <md-button ng-click="vm.save()" class="md-primary">Save</md-button>
      </div>
    </md-dialog>
  </script>
</div>

JS

angular.module('app',['ngMaterial'])

.controller('MyController', function($scope, $mdDialog) {
  this.open = function(ev) {
    this.showText = false;
    $mdDialog.show(
      {
        templateUrl: "test.html",
        clickOutsideToClose: true,
        scope: $scope,
        preserveScope: true,
        controller: function($scope) {
       },
    });
  };

  this.save = function () {
    this.showText = true;
    $mdDialog.cancel();
  }
})

Demo:

https://material.angularjs.org/latest/demo/input

Docs:

https://material.angularjs.org/latest/api/directive/mdDialog https://material.angularjs.org/latest/api/service/$mdDialog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.