The purpose of this plunk is to translate the elements in the Angular UI Modal from the controller, where the modal is wrapped with a directive. The solution must meet the following assumptions:
- The directive announces the transition of fields. These fields are included in the directive declaration in the HTML markup of the controller.
- These fields declared in the controller must be displayed in the module.
- The scope of these fields should be available in the controller (see that I declared the variable
input1 in the controller, which should set the value to Modal). - I defined a
content element to overlap the fields. This item is in a modal template. I am not sure when this template is available for transmission.
To summarize, the goal is to have a set of fields declared in the markup of the HTML controller, and available in modal mode, where the modal ends in the directive, and the control area is managed in the controller. Any ideas would be highly appreciated.
HTML
<div the-modal control="modalCtl"> <p>some text</p> <input type="text" ng-model="input1" /> </div> <button type="button" ng-click="open()">Open me!</button>
Javascript
var app = angular.module("app", ['ui.bootstrap']); app.controller("ctl", function($scope,$timeout) { $scope.modalCtl = {}; $scope.input1 = "abc"; $scope.open = function(){ $scope.modalCtl.openModal(); }; }); app.directive("theModal", function($uibModal) { return { restrict: "AE", scope: { control: "=" }, transclude: true, link: function (scope, element, attrs, ctrl, transclude) { scope.control = scope.control || {} scope.control.openModal = function () { scope.instance = $uibModal.open({ animation: false, scope: scope, template: '<div>in the template</div><div class="content"></div>' }); element.find('.content').append(transclude()); }; } } });
source share