I have a modal controller, like so
angular.module('myApp').controller('ModalDemoCtrl', function ($scope, $modal, $log) {
$scope.arrayList = [];
$scope.newItem = function () {
var modalInstance = $modal.open({
templateUrl: 'newItem.html',
controller: 'newItemCtrl',
windowClass: 'app-modal-window',
backdrop: 'static',
resolve: {
}
});
modalInstance.result.then(function (editable) {
console.log($scope.arrayList);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.newArrayItem = function () {
var modalInstance = $modal.open({
templateUrl: 'newArrayItem.html',
controller: 'newArrayCtrl',
windowClass: 'app-modal-window',
backdrop: 'static',
resolve: {
}
});
modalInstance.result.then(function (editable) {
$scope.arrayList.push(editable);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
When i first open a modal window it's to create a 'newItem', then inside that window I open another modal to create 'ArrayItems', when one arrayItem is created (when that modal is closed) I want to push that item to my $scope.arrayList
, and repeat, when all arrayItems are created I also close the 'newItem' modal, and this is where I would like to reach my $scope.arrayList
, but when I try to log it, it's empty.
So I guess I will need to push the objects to the parent scope, how do I do this?
$scope.arrayList
it's not the same in each of the modals. To make it work you can try to put arrayList on$rootScope.arrayList
instead, that's a dirty and fast fix, there are better solutions.