Created
November 15, 2016 00:14
-
-
Save jrwebdev/db3730209f89cc6a831643b22ccd6e49 to your computer and use it in GitHub Desktop.
Angular 1 vs Angular 2 Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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