Brand new with AngularJS (and AngularJS UI) and I cannot close the modal window.
The HTML code is as follows:
<div>
<div data-ng-show="agencies || agencies.length > 0">
<div>
<h3>
Agencies
</h3>
</div>
<div>
<a href="" data-ng-click="showModalAddAgency()"><span class="glyphicon glyphicon-cloud-upload"></span> Add</a>
</div>
</div>
</div>
Controller:
'use strict';
app.controller('agencyController', function ($scope, $modal, agenciesDataService) {
$scope.agencies = [];
$scope.agency = null;
init();
function init() {
getAgencies();
};
function getAgencies() {
var onResponse = function (results) {
$scope.agencies = results.data;
};
var onError = function (error) {
alert(error.message);
};
agenciesDataService.getAgencies()
.then(onResponse, onError);
};
$scope.showModalAddAgency = function () {
var modalInstance = $modal.open({
templateUrl: 'app/views/agencydetail.html',
controller: 'agencyController',
backdrop: 'static'
});
};
$scope.addAgency = function addAgency() {
var currentAgency = this.agency;
var onResponse = function (results) {
currentAgency.Id = results.data.Id;
currentAgency.Name = results.data.Name;
currentAgency.AgencyPortalAccountId = results.data.AgencyPortalAccountId;
$scope.agencies.push(currentAgency);
currentAgency = {};
};
var onError = function (error) {
}
agenciesDataService.addAgency(currentAgency)
.then(onResponse, onError);
};
});
Pretty much after a POST request, I want to close the modal window, but I don't know how to do it. I don’t know how I can refer to the modal window that I opened.
Any insight was appreciated.
Update: My html modal includes a Save and Cancel button.
<div class="modal-footer">
<button class="btn btn-primary normal-button"
ng-click="addAgency()">Save</button>
<button class="btn btn-warning" ng-click="$dismiss()" style="width:100px;">Cancel</button>
</div>
The modal closes when I click the "Cancel" button. What I want to achieve is the ability to close the modality when the addAgency function is complete.
source
share