Hi,
I'm quite new to Angular and I have a question as I'm trying to structure a
bit my code.
I'm defining different controllers handling data coming from same SQL table
but differenciated thanks to a type.
repository.controller('RepositoryLogicalGatesController', ['$http',
function ($http) {
this.whatAmI = 'Logical Gates';
var repo = this;
repo.listOfObjects= [];
$http.get('http://localhost:62844/api/RepositoryLogicalGate').success(function
(data) { repo.listOfObjects = data; })
}]);
app.controller('RepositoryBooleanFunctionsController', ['$http', function
($http) {
this.whatAmI = 'Boolean Functions';
var repo = this;
repo.listOfObjects = [];
$http.get('http://localhost:62844/api/RepositoryBooleanFunction').success(function
(data) { repo.listOfObjects = data; })
}]);
I would like to use a mutualized service having a parameter to call one URL
or the other based on this.
I tried the following
repoSrv.provider('LoadRepository', ['$http', function
LoadRepositoryProvider($http) {
var repoType;
this.init = function (rt) {
repoType = rt;
};
this.$get = function () {
data = [];
switch (repoType) {
case 'logicalgate':
data=
$http.get('http://localhost:62844/api/RepositoryLogicalGate');
break;
case 'booleanfunction':
data =
$http.get('http://localhost:62844/api/RepositoryBooleanFunction');
break;
default:
data = [];
break;
}
return {
getRepositoryObjects: function (value) {
return data;
}
}
}
}])
but I'm stuck with errors related on unknown $http.
Could anyone share an example if a service handling parameter AND $http
service ?
Or give me some ressources with detailed explanation about services ?
Angular JS documentation is not clear to me and all tutorials I found are
quite simple for services
Any helpl is very welcomed.
Thanks
Cyril
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.