Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Created November 15, 2016 00:14
Show Gist options
  • Save jrwebdev/db3730209f89cc6a831643b22ccd6e49 to your computer and use it in GitHub Desktop.
Save jrwebdev/db3730209f89cc6a831643b22ccd6e49 to your computer and use it in GitHub Desktop.
Angular 1 vs Angular 2 Services
// Angular 1
const module = angular.module('myModule', []);
module.service('UserService', ['$http', function ($http) {
this.getUsers = () => {
// Code to retrieve users here
}
}]);
/***************************************************************/
// Angular 2
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
class UserService {
constructor(private http: Http) {}
getUsers() {
// Code to retrieve users here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment