AngularJS Dialog component

In this example below you will see how to do a AngularJS Dialog component with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 01abhishekjain, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 01abhishekjain ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>AngularJS Dialog component</title>
  
  
  
  
  
</head>

<body>

  <div ng-app="app" ng-controller="ctrl">
  <button ng-click="show=!show">show/hide toggle</button>

  <dialog-x title="Hello {{username}}." visible="show" on-cancel="show = false" on-ok="show = false; doSomething()">
    Body goes here: {{username}} is {{title}}.
  </dialog-x>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.6/angular.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/01abhishekjain/angularjs-dialog-component-JMzELg */
var app = angular.module("app", []);

app.controller("ctrl", function($scope) {
  $scope.username = "abhishek";
  $scope.title = "fighter";
  $scope.show = false;
  $scope.doSomething = function() {
    alert(123);
  };
});

app.directive("dialogX", function() {
  return {
    restrict: "E",
    transclude: true,
    scope: {
      visible: "=",
      title: "@",
      onOk: "&",
      onCancel: "&"
    },
    template: `<div ng-show="visible">
  <h3>{{title}}</h3>
  <div class="body" ng-transclude></div>
  <div class="footer">
    <button ng-click="onOk()">Save changes</button>
    <button ng-click="onCancel()">Close</button>
  </div>
</div>`
  };
});

Comments