I know this has been asked multiple times, i'm trying to share dynamic data with multiple controllers.
Sharing static data was working fine, when i add $http i lost the way.
Below is the demo where i'm trying to implement similar approach.
Demo is working based on static array, i have specified github endpoint which gives similar data. How to make this demo work based on dynamic data.
```
var myApp = angular.module('myApp', []);
myApp.factory('Data', function () {
return { filtercards: 'Default Data' };
});
myApp.factory('DynamicData', function ($q, $http) {
var dynamicdataObj = {};
dynamicdataObj.getDynamicData = function(type){
var url = 'https://api.github.com/users/tomalex0/repos'
$http({
method: 'GET',
url: url
}).then(function successCallback(response) {
}, function errorCallback(response) {
});
};
//dynamicdataObj.lists = dynamicdataObj.getDynamicData('GOOG')
dynamicdataObj.lists = [{
id : 1,
name : 'First',
watchers_count :5
},{
id : 2,
name : 'Second'
}];
return dynamicdataObj;
});
function FirstCtrl($scope, Data, DynamicData) {
$scope.data = Data;
$scope.lists = DynamicData.lists;
$scope.toggleLike = function(item){
item.watchers_count = (item.watchers_count) ? (item.watchers_count+1) : 1;
}
}
function SecondCtrl($scope, Data, DynamicData) {
$scope.data = Data;
$scope.lists = DynamicData.lists;
}
```