I would like to inject a custom http service in my embedded task form application.
Herewith is the code snippet:
<script cam-script type="text/form-script">
inject([ '$scope', '$http', function($scope, $http) {
camForm.on('form-loaded', function() {
// Custom service call
$http.get('http://localhost:8888/books/1').then(function(response){
alert(JSON.stringify(response.data));
});
});
}]);
When the form loads the http://localhost:8888/books/1 isn't invoked and I don't know why.
For anybody else running into the same issue here is the code snippet that made debugging a bit easier:
<script cam-script type="text/form-script">
debugger;
inject([ '$scope', '$http', function($scope, $http) {
camForm.on('form-loaded', function() {
$http({
method: 'GET',
url: 'http://localhost:8888/books/1'
}).then(
function successCallback(response)
{
alert('SUCCESS :-) ' + angular.toJson(response.data));
$scope.data = response.data
},
function errorCallback(response) {
alert('FAILED :-( ' + response.status);
});
});
}]);
</script>
As for the solution, I had to enable CORS on the server that was receiving the request. See https://spring.io/guides/gs/rest-service-cors/