When I call a factory method within the controller it's fine- but when I call a factory method within a controller method it's undefined.
Here's my factory:
app.factory('config', ['$http', '$interval', function($http, $interval, $scope) {
return {
lines: function() {
return $http({
url: appPath+'/config.php?data=lines',
method: 'JSON'
})
},
updateLines: function() {
$http.post(appPath+'/write.php?handler=update line', $scope.lines).
success(function(data, status, headers, config) {
return true;
}).error(function(data, status, headers, config) {
return false;
});
}
}
}]);
My Controller:
app.controller('lineController', function($scope, $interval, $http, config) {
// this works fine
config.lines().success(function(data) {
$scope.lines=data;
});
this.addToLine = function(line, customer) {
};
this.unassign = function(customer, line) {
var index = line.indexOf(customer);
line.splice(index, 1);
// Cannot read property 'lines' of undefined
config.updateLines();
};
});
Inside the controller scope my factory config is defined, however when referencing config in a method the factory is undefined. AngularJs is new to me, so if this is bad practice then I'd appreciate being pointed in the right direction.
Thanks