| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-04-27 11:28:22 -07:00
										 |  |  | import {Injectable} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | export class UserService { | 
					
						
							|  |  |  |   // Todo: get the user; don't 'new' it.
 | 
					
						
							|  |  |  |   private _alice = new User('Alice', true); | 
					
						
							|  |  |  |   private _bob = new User('Bob', false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // initial user is Bob
 | 
					
						
							|  |  |  |   user = this._bob; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // swaps users
 | 
					
						
							|  |  |  |   getNewUser() { | 
					
						
							|  |  |  |     return this.user = this.user === this._bob ? this._alice : this._bob; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class User { | 
					
						
							|  |  |  |   constructor( | 
					
						
							|  |  |  |     public name:string, | 
					
						
							|  |  |  |     public isAuthorized:boolean = false) { } | 
					
						
							|  |  |  | } |