Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div layout="column" layout-fill layout-align="center center"
  ng-controller="MyCtrl" ng-cloak>
  <div>{{user|json}}</div>
  <md-button class="md-primary md-raised demo-dialog-open-button"
    ng-click="openWin()">
    Dialog
  </md-button>
</div>
              
            
!

CSS

              
                .dialog {
  max-width: 800px;
  min-width: 480px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 7px 8px -4px rgba(0, 0, 0, 0.2), 0 13px 19px 2px rgba(0, 0, 0, 0.14), 0 5px 24px 4px rgba(0, 0, 0, 0.12);
}
.dialog .dialog-content {
  margin: 8px 24px;
}
.dialog .dialog-footer {
  margin-top: 24px;
  margin-bottom: 16px;
}
              
            
!

JS

              
                angular
  .module('myApp', ['ngMaterial', 'ngMessages'])
  .config(function($mdThemingProvider) {
    // 设置公用的主题
    $mdThemingProvider.theme('default')
      .primaryPalette('blue');
  })
  .run(function($templateCache) {
    $templateCache.put('template/form.html',
      '<ria-dialog class="user-dialog" dialog-title="Edit User">\n' +
      '  <form name="userForm" class="dialog-content"\n' +
      '    layout="column" novalidate ng-controller="UserFormCtrl">\n' +
      '\n' +
      '    <md-input-container>\n' +
      '      <label>Email</label>\n' +
      '      <input md-maxlength="30" name="email" ng-model="email"\n' +
      '        ng-required="true" minlength="10" maxlength="100" ng-pattern="/^.+@.+\\..+$/">\n' +
      '      <div ng-messages="userForm.email.$error" role="alert">\n' +
      '        <div ng-message-exp="[\'required\', \'minlength\', \'maxlength\', \'pattern\']">\n' +
      '          Your email must be between 10 and 100 characters long and valid.\n' +
      '        </div>\n' +
      '      </div>\n' +
      '    </md-input-container>\n' +
      '\n' +
      '    <md-input-container>\n' +
      '      <label>Name</label>\n' +
      '      <input name="userName" ng-required="true" ng-model="userName">\n' +
      '      <div ng-messages="userForm.userName.$error">\n' +
      '        <div ng-message="required">This is required.</div>\n' +
      '      </div>\n' +
      '    </md-input-container>\n' +
      '    <div layout="row" layout-align="end">\n' +
      '      <md-button type="submit" class="md-primary md-raised"\n' +
      '        ng-disabled="userForm.$invalid" ng-click="saveUser()">Submit\n' +
      '      </md-button>\n' +
      '    </div>\n' +
      '  </form>\n' +
      '</ria-dialog>');
  })

  /**
   * 模态窗指令:对应模态窗服务的视图
   * @param  dialogTitle {String} 设置障碍模态窗标题
   */
  .directive('riaDialog', function() {
    return {
      scope: {
        dialogTitle: '@'
      },
      restrict: "EA",
      transclude: true,
      replace: true,
      template: '<div class="dialog" role="dialog" aria-label="Dialog" layout="column" ng-cloak>\n' +
      '  <md-toolbar class="dialog-header">\n' +
      '    <div class="md-toolbar-tools" layout="row" layout-align="space-between center">\n' +
      '      <h4>{{::dialogTitle}}</h4>\n' +
      '      <md-button class="md-icon-button" title="Close"\n' +
      '        aria-label="Close dialog"\n' +
      '        ng-click="$parent.closeDialog();">\n' +
      '        <md-icon>\n' +
      '          <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fit="" preserveAspectRatio="xMidYMid meet" focusable="false">\n' +
      '            <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>\n' +
      '          </svg>\n' +
      '        </md-icon>\n' +
      '      </md-button>\n' +
      '    </div>\n' +
      '  </md-toolbar>\n' +
      '  <ng-transclude></ng-transclude>\n' +
      '</div>\n'
    };
  })

  .factory('dialog', function($mdPanel) {
    return {
      /**
       * 打开带模板的模态窗
       * @param templateUrl {String} 内容模块地址
       * @param locals {Object} 指定共享数据
       * @param hasBackdrop {Boolean} 点击模态窗外面关闭
       */
      open: function(templateUrl, locals, clickOutsideToClose) {
        var panelRef = null;
        var position = $mdPanel.newPanelPosition()
          .absolute()
          .center();

        var config = {
          attachTo: 'body',
          controller: ['$scope', function($scope) {
            $scope.locals = locals;
            $scope.closeDialog = function() {
              panelRef && panelRef.close().then(function() {
                panelRef.destroy();
              });
            }
          }],
          templateUrl: templateUrl,
          hasBackdrop: true,
          panelClass: 'ria-dialog',
          position: position,
          trapFocus: false,
          zIndex: 40,
          clickOutsideToClose: clickOutsideToClose || false,
          escapeToClose: true,
          focusOnOpen: true
        };

        return $mdPanel.open(config).then(function(mdPanelRef) {
          panelRef = mdPanelRef;
        });
      }
    }
  })

  .controller('MyCtrl', function($scope, dialog) {
    $scope.user = {
      email: 'riafan@163.com',
      userName: 'Flying'
    };
    $scope.openWin = function() {
      dialog.open('template/form.html', $scope.user);
    };
    // first time open the panel
    $scope.openWin();
  })

  .controller('UserFormCtrl', function($scope) {
    var user = $scope.$parent.locals;
    $scope.email = user.email;
    $scope.userName = user.userName;
    $scope.saveUser = function() {
      $scope.closeDialog();
      user.email = $scope.email;
      user.userName = $scope.userName;
    };
  });


angular.element(document).ready(function() {
  angular.bootstrap(document, ['myApp']);
});

              
            
!
999px

Console