I'm new to AngularJs and encountered a problem while trying to avoid writing the same code in different controllers.
I've created a factory that should hold all functions, while the controllers are able to use these functions, and moved a function to that factory from the controller. I created a function which should post data from a form, but when I click on it to execute, literally nothing happens.
I've searched quite a while on google and stackoverflow and couldn't find any issue that fits my problem.
Is there something I missed or did wrong?
Factory:
(function(){
angular.module("myApp").factory('appServicesProvider',function( $http ) {
var restURL = "http://localhost:8080/Project/rest/api/";
function postFunction(data){
$http.post(restURL, JSON.stringify(data)).then(
function(response){
}
);
}
return{postFunction:postFunction}
});
})();
Controller:
(function() {
angular.module("myApp")
.controller("AdminController",function($scope, $http, appServicesProvider) {
$scope.restURL = "http://localhost:8080/Project/rest/api/";
)}; // There's more code but it's irrelevant to the function I'm talking
about
HTML:
<div id="postFunctionDiv" class="form-group row">
<div class="col-xs-4">
<label>PostFunction</label>
<!---
Some form inputs
---!>
<button class="btn btn-success" ng-
click="appServicesProvider.postFunction(data)" >Execute</button>
</div>