I have a register form inside a modal. When I submit the form inside the modal I want to push the saved item in the array $scope.lists = []. The $scope.lists is inside the ListsController and I have the submit function inside the ModalsController.
angular.module('app')
.controller('ListsController', function ($scope, listsRegister, $uibModal) {
$scope.lists = [];
$scope.openFormListModal = function () {
var modalInstance = $uibModal.open({
...,
controller: function ($scope, $uibModalInstance) {
// Submiting the form
$scope.submit = function () {
listsRegister.register($scope.list)
.then(function (response) {
if (response.insert) {
$scope.form.$setPristine();
$scope.form.$setUntouched();
$scope.list = {};
// $scope.lists.push(response); <- Is it possible to access the lists from the ListsController inside this Modal's Controller?
}
})
.catch(function (error) {
console.log(error);
});
};
},
size: 'sm',
});
};
});
Is there a good way to access the $scope from the ListsController? I need to update the $scope.lists array after saving the data.