Why angular says me that setData is not a function?
angular.module('mdl').factory('DataService', ['$http', '$cookieStore', '$rootScope',
function ($http, $cookieStore, $rootScope) {
return {
setData: function (data) {
$rootScope.data = data;
},
};
}
]);
Here is my controller which calls setData.
angular.module('mdl').controller('DataCtrl', ['$scope', '$http', '$location', '$rootScope', 'DataService',
function($scope, $http, $location, DataService) {
$scope.getData = function (id) {
$http.post('/rest/data/get', id)
.success(function (data, status, headers, config) {
DataService.setData(data);
$location.path('/main');
})
.error(function (data, status, headers, config) {
});
};
}
]);