I am encountering an issue with sharing a $scope object between two controllers.
Within the 'IssueBookCtrl' controller, I update the 'books' object element value like this:
$scope.books[i].issued = true;
After that, I use the $emit service to share the $scope object with the 'BookListCtrl_Librarian' controller.
$scope.$emit('update_parent_controller', $scope.books);
However, when I view the page associated with the 'BookListCtrl_Librarian' controller, I do not see the updated object.
In the controller.js file:
Controllers.controller('BookListCtrl_Librarian', ['$scope','$http','$location','$rootScope','BookData',
function ($scope, $http ,$location, $rootScope , BookData) {
$http.get('data/books.json').success(function(data) {
if($rootScope.books==='undefined'){
$rootScope.books = BookData.getData();
}
$scope.books = data;
});
$scope.options = ['bookId', 'cost'];
$scope.$on("update_parent_controller", function(event, books){
$scope.books = books;
});
// Other functions defined here...
}]);
Controllers.controller('IssueBookCtrl', ['$scope','$rootScope','$http','$routeParams','$location',
function ($scope,$rootScope, $http, $routeParams, $location) {
var Id=$routeParams.bookId;
$http.get('data/books.json').success(function(data) {
$scope.books = data;
});
// Issue and other functions defined here...
}]);
Your guidance on this matter would be greatly appreciated.
Thank you!