37 lines
561 B
Markdown
37 lines
561 B
Markdown
# .cadoles-slide-title[Les services (2/)]
|
|
|
|
**Création de services**
|
|
|
|
.cadoles-xs[
|
|
```js
|
|
|
|
var MyApp = angular.module('MyApp', []);
|
|
|
|
// Création d'un service via une fonction génératrice (la plus classique)
|
|
|
|
MyApp.factory('myService', ['$http', function($http) {
|
|
|
|
var myServiceAPI = {
|
|
|
|
myServiceMethod: function() {
|
|
console.log('Foo !');
|
|
}
|
|
|
|
};
|
|
|
|
return myServiceAPI;
|
|
|
|
}]);
|
|
|
|
// Via un constructeur
|
|
|
|
MyApp.service('myOtherService', ['$http', function($http) {
|
|
|
|
this.myServiceMethod = function() {
|
|
console.log('Foo !');
|
|
};
|
|
|
|
}]);
|
|
```
|
|
]
|