<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-app="app">
<div ng-controller="AppCtrl as ctrl">
<outer>
<popup-on-click>
<div class="modal-header">
<h3 class="modal-title">title</h3>
</div>
<div class="modal-body">
<inner>
content
</inner>
</div>
<div class="modal-footer">
footer
</div>
</popup-on-click>
</outer>
</div>
</div>
</body>
</html>
// Code goes here
(function (ng, undefined){
'use strict';
var NG_HIDE_CLASS = 'ng-hide';
var module = ng.module('test', []);
module
.directive('outer', [function() {
function ctrl() {
this.outerFunctionality = function() {
alert('context call');
};
}
function link(scope, element, attr) {
}
return {
restrict: 'E',
controller: ctrl,
link: link
};
}])
.directive('inner', [function() {
function link(scope, element, attr, outerCtrl) {
scope.ok = function() {
if (!outerCtrl) {
alert('what happend to my outer ctrl?');
} else {
outerCtrl.outerFunctionality();
}
};
}
return {
restrict: 'E',
require: '^?outer',
link: link,
template: '<button ng-click="ok()" class="btn btn-primary">ok</button> <button ng-click="cancel()" class="btn btn-secondary">cancel</button>'
};
}])
.directive('popupOnClick', ['$modal', function($modal) {
function srModalInstanceCtrl($scope, $modalInstance) {
$scope.ok = function () {
$modalInstance.close($scope.row);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}
function link(scope, element, attr, ctrl, transcludeFn) {
var popupChild = element.find('div');
var template = popupChild.html();
popupChild.addClass(NG_HIDE_CLASS);
scope.openPopup = function() {
var modalInstance = $modal.open({
animation: true,
template: template,
//futureParentEl: element,
controller: srModalInstanceCtrl,
size: 'lg',
scope: scope
});
modalInstance.result.then(function () {
//action on close ok
}, function () {
//action on cancel
});
};
}
return {
restrict: 'E',
scope: true,
transclude: true,
link: link,
template: '<button ng-click="openPopup()" class="btn btn-primary">Open Popup</button><div ng-transclude></div>'
};
}]);
ng.module('app', ['ui.bootstrap', 'test']);
ng.module('app')
.controller('AppCtrl', [function () {
}]);
})(angular);
/* Styles go here */