Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="MainCtrl">
  <button ng-click="modal.toggle('Hello there', 'this is a modal')">Popup</button>
  
  
  
  <div my-modal></div> 
  
</body>
</html>
 
.modal {
  position: fixed;
  top: 20%;
  width: 100%;
  text-align: center;
  padding: 10px;
  background-color: red; 
}
 
var app = angular.module('app', []);
app.controller('MainCtrl', function ($scope) {
  
  
    
});
app.directive('myModal', ['$rootScope', function ($rootScope) {
  return {
    restric: 'A',
    replace: true,
    template: '<div class="modal" ng-show="modal.show">{{ modal.mainMessage }}<br /><button ng-click="modal.toggle()">Close</button></div>',
    link: function (scope, elm, attrs) {
      $rootScope.modal= {
        mainMessage: '',
        subMessage: '',
        show: false,
        toggle: function (mainMessage, submessage) {
           this.mainMessage = mainMessage;
           this.submessage = submessage;
           this.show = !this.show;
        }
      
      };
    }
  };
  
}]);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers