Patrice Chalin 05864c2584 docs(dependency-injection): revised Dart and TS code and prose (#1573)
docs(dependency-injection): revise Dart and TS code and prose
2016-06-03 11:16:46 -07:00

23 lines
450 B
TypeScript

// #docregion
import {Injectable} from '@angular/core';
export class User {
constructor(
public name:string,
public isAuthorized:boolean = false) { }
}
// Todo: get the user; don't 'new' it.
let alice = new User('Alice', true);
let bob = new User('Bob', false);
@Injectable()
export class UserService {
user = bob; // initial user is Bob
// swap users
getNewUser() {
return this.user = this.user === bob ? alice : bob;
}
}