Whenever I run the app implemented by angularjs 1.4.3.
BannerService.js
app.service('BannerService',function ($http) {
this.save = function saveBanner(banner) {
return $http({
method: 'POST',
url: 'http://localhost:8081/api/banners'
});
}
});
BannerController.js
app.controller('BannerAddCtrl', ['$scope','$log','BannerService',
function ($scope,$log, BannerService) {
$scope.save = function() {
BannerService.saveBanner(myBanner)
.success(function (result) {
$log.debug('RESULT', result);
}, function (reason) {
$log.debug('REASON', reason);
});
}
}]);
And index.html
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-block" ng-click="save()">Save Banner</button>
</div>
It throws an exception as below:
TypeError: BannerService.saveBanner is not a function
at ChildScope.$scope.save (bannerControllers.js:64)
at fn (eval at compile (angular.js:13145), <anonymous>:4:203)
at callback (angular.js:23298)
at ChildScope.$eval (angular.js:15846)
at ChildScope.$apply (angular.js:15945)
at HTMLButtonElement.<anonymous> (angular.js:23303)
at HTMLButtonElement.dispatch (jquery.js:4435)
at HTMLButtonElement.elemData.handle (jquery.js:4121)
Can someone help me why I get the error. Greatly appreciate your time.