I attempted to share data between two controllers by using a factory. However, it seems that the data is not being shared properly between the two inputs. In the AppCtrl controller, I set Data.FirstName
to be equal to lattitude
. But when I switch over to the PathController, I am unable to access the value stored in Data.FirstName
.
Could someone please point out what might be causing this issue in my code?
.factory('Data', function(){
return { FirstName: 'jjjj' };
})
// controller one
.controller('AppCtrl', function($scope, Data, $http, $ionicModal, $timeout) {
....
$scope.mapLocation = function(lattitude, longittude) {
Data.FirstName = lattitude;
$scope.Data = Data;
}
....
})
// controller two
.controller("PathController", [ '$scope', function($scope, Data) {
$scope.Data = Data;
console.log(Data.FirstName); // Issue with getting Data.FirstName
angular.extend($scope, {
center: {
lat: 35.720031000963,
lng: -87.343068987131,
zoom: 17
},
markers: {
Campus: {
lat: 35.728031000963,
lng: -87.343068987131,
focus: true,
draggable: false,
message: "Building1"
},
},
defaults: {
scrollWheelZoom: false
}
});
}])