I have a mdDialog inside of my application that makes a call to an API which responds with some data. I need this data response to be accessible in the main controller so that it can be used in another call.
CRUD operation
$scope.add_id = [];
$scope.createAddress = function() {
$http.get('api.php?action=create-address', {
params: {
add1: $scope.newadd.add1,
add2: $scope.newadd.address2,
city: $scope.newadd.city,
state: $scope.newadd.state,
zip: $scope.newadd.zip
}
})
.success(function(response) {
$scope.add_id = response.data[0].address_id;
});
};
mdDialog
$scope.addParcel = function(ev) {
$mdDialog.show({
controller: DialogController,
templateUrl: 'libs/html/addparcel.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose:true,
scope: $scope,
preserveScope: true
});
};
So inside of the addParcel mdDialog I have a button that executes the addAddress function and it turns successful and I can access the data within the dialog. However, even though the dialog is set to preserve the scope, the address_id does not appear at all in the main controller after I close the dialog. Am I supposed to use locals? How can I get the data to be accessible in the main controller? Please be as informative as possible as I am still new to AngularJS. Thanks.