I am trying to create factory and use it in the controller, the factory return data from get method and save it in the controller but its not working, and $scope.myData return undefind.
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, myService) {
$scope.myData = myService.getEvent();
});
app.factory('myService', function($http){
var oGetData = {};
oGetData.getEvent = function(){
$http.get('http://citysdk.dmci.hva.nl/CitySDK/events/search?category=festival')
.then(function(response) {
return response.data.event;
});
};
return oGetData ;
});
when i use factory code directly in the controller its work fine
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get('http://citysdk.dmci.hva.nl/CitySDK/events/search?category=festival')
.then(function(response) {
$scope.myData = response.data.event;
});
});
can someone tell me what i did wrong in the first code please?
here is the codepen http://codepen.io/anon/pen/NRVZdE