Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just noticed you said with "only angularjs". My answer uses bootstrap for ease of making a popup on the same page. You can write your own HTML/CSS to mimic bootstrap if you don't want to use other frameworks. The concept still applies.</p> <p>I put together a jsfiddle that uses twitter bootstrap for its modal (note Twitter Bootstrap also requires jQuery). This way you can maintain SPA architecture. <a href="http://jsfiddle.net/patrickdubs/UHg95/8/" rel="nofollow">http://jsfiddle.net/patrickdubs/UHg95/8/</a></p> <p>I created a directive for the modalWindow that will augment functions onto the userService. This way, each individual controller can call popupWin on the userService. I'm only demonstrating with "First Name" field, but this can easily be extended to meet whatever needs you have.</p> <pre><code>marketApp.directive("modalWindow", ["userService", function (userService) { var isOpen = false; return { restrict: "AE", replace: "true", scope: {user-data: '='}, template: '&lt;div class="modal fade"&gt;&lt;div class="modal-dialog"&gt;&lt;div class="modal-content"&gt;&lt;div class="modal-header"&gt;&lt;h4 class="modal-title"&gt;User Service&lt;/h4&gt;&lt;/div&gt;&lt;div class="modal-body"&gt;&lt;p&gt;First Name: &lt;input type="text" ng-model="data.firstName" /&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="modal-footer"&gt;&lt;button type="button" class="btn btn-default" ng-click="closeWin()"&gt;Close&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;', link: function (scope, element, attrs) { scope.closeWin = function () { if (!isOpen) { return; } element.modal("hide"); scope.userData.firstName = scope.data.firstName; isOpen = false; } userService.popupWin = function () { if (isOpen) { return; } element.modal("show"); isOpen = true; } userService.isOpen = function () { return isOpen; } } } }]); </code></pre> <p>Then in your controller, just create an object to pass to user-data in the modal:</p> <pre><code>marketApp.controller('loginCtrl', ['$scope', '$http', 'userService', function ($scope, $http, userService) { $scope.d = {}; $scope.openPopUp = function () { if( !userService.isOpen() ) { userService.popupWin(); } } }]); </code></pre> <p>And the HTML:</p> <pre><code>&lt;div ng-app="marketApp" ng-controller="loginCtrl"&gt; &lt;div modal-window user-data="d"&gt;&lt;/div&gt; &lt;button ng-click="openPopUp()"&gt;Open Popup&lt;/button&gt; &lt;p&gt;First Name From Popup: {{d.firstName}}&lt;/p&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload