Hope someone can clarify something for me. What I am doing right now, working with Angular 1.4.6:
I create a service
'use strict';
angular.module('App')
.factory('processingService', ['$http',
function ($http) {
var settings = 'Settings/GetSettings';
var getSettings = function()
{
return $http.get(settings)
.then(function(response)
{
return response.data;
});
};
return {
getSettings: getSettings
};
}
]);
And use/inject that in my controller.
'use strict';
angular.module('App')
.controller('appController', [
'$scope','appService',
function ($scope, appService) {
var onSettings = function (data) {
if (data.hasOwnProperty('Settings')) {
//Code handling Settings
}
};
var onSettingsError = function()
{
//Handle Errors
$scope.showLoader = false;
};
appService.getSettings()
.then(onSettings, onSettingsError);
}]);
I started a little bit playing around with angular2 beta and found the following example on http.get
getRandomQuote() {
this.http.get('http://localhost:3001/api/random-quote')
.map(res => res.text())
.subscribe(
data => this.randomQuote = data,
err => this.logError(err),
() => console.log('Random Quote Complete')
);
}
logError(err) {
console.error('There was an error: ' + err);
}
I build some other methods and tested a bit around and googled a lot, but could not find anything similar in creating a service with angular2 beta and typescript the way I was doing till now. Is it even necessary to do it that way. Or is this not the way it is done now with Angular2 beta?
Thank you in advance.