Im trying out a simple http app using Angularjs. My code is
var studentApp = angular.module('studentApp',['ui.bootstrap']);
studentApp.factory('studentSession', function($http){
return {
getSessions: function() {
return $http.post('/services', {
type : 'getSource',
ID : 'TP001'
});
}
}
});
studentApp.controller('studentMenu',function($scope, studentSession){
studentSession.getSessions().success($scope.handleSuccess);
$scope.handleSuccess = function(data, status) {
console.log(data);
};
});
While trying to run above code, i get the error Undefined is not a function in chrome . Searching through stackoverflow the recommended fix is to provide scope for function. Error persists even after scoping the function.
Suspected problem with corrupt angular file, Since the code works fine if i move the getSession code inside controller. But the error persists on angular version 1.0.6 and 1.1.4(both uncompressed and minified version).
The error varies in firefox. its fn is not a function with uncompressed angularjs and b is not a function with minified angularjs.
any suggestion on how to fix this issue?
$scope.handleSuccessis undefined when you passed it to.success(). Just put the handler above the rest of your code in the controller.