In an attempt to resolve a problem synchronizing between controllers. I was trying to follow the solution provided here:
For some reason with my setup this doesn't seem to work for me. My controllers are returning either empty or its just simply not working. Would anyone know why this approach wouldn't work?
Main controller:
GDI_App.controller('Form_Controller', function ($scope, Service) {
Service.get_data();
//What I tried so far:
$scope.Current.incidents = Service.Current.data; //returns nothing.
$scope.Current.incidents = Service.current_data(); //returns [];
});
Service:
GDI_App.factory('Service', function($q) {
var Current ={}
Current.Data = [];
return{
get_data: function(){
var Fake_Data = [
{ "Data1": "123123", "Data2": "15437" },
{ "Data1": "432234", "Data2": "146" },
{ "Data1": "45654", "Data2": "3534" },
{ "Data1": "76587", "Data2": "78978" },
{ "Data1": "2342", "Data2": "5345878" },
{ "Data1": "178", "Data2": "34534" },
{ "Data1": "173838", "Data2": "354534" },
];
return $q.when(Fake_Data)
.then(function(data) {
angular.copy(data, Current.Data);
});
}
current_data: function(){
return Current.Data;
}
}
});