Day 2 training code
In-memory service calling restful service Routing Intro Angular CLI Basics
Showing
26 changed files
with
121 additions
and
253 deletions
@@ -41,4 +41,7 @@ | @@ -41,4 +41,7 @@ | ||
41 | </div>--> | 41 | </div>--> |
42 | 42 | ||
43 | <!--Multiple Components--> | 43 | <!--Multiple Components--> |
44 | -<hero-detail [hero]="selectedHero"></hero-detail> | 44 | +<!--<hero-detail [hero]="selectedHero"></hero-detail>--> |
45 | + | ||
46 | +<router-outlet></router-outlet> | ||
47 | +<!--Routed view go here--> |
src/app/app.component.js
deleted
100644 → 0
1 | -"use strict"; | ||
2 | -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
3 | - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
4 | - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
5 | - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
6 | - return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
7 | -}; | ||
8 | -var __metadata = (this && this.__metadata) || function (k, v) { | ||
9 | - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
10 | -}; | ||
11 | -var core_1 = require("@angular/core"); | ||
12 | -var hero_service_1 = require("./services/hero.service"); | ||
13 | -var AppComponent = (function () { | ||
14 | - // constructor(private heroService: HeroService){ | ||
15 | - // // this.heroes=heroService.getHeroes(); | ||
16 | - // // Async services and Promises | ||
17 | - // this.heroService.getHeroesSlowly().then(heroes => this.heroes = heroes); | ||
18 | - // } | ||
19 | - // //ngOnInit | ||
20 | - function AppComponent(heroService) { | ||
21 | - this.heroService = heroService; | ||
22 | - this.name = 'Angular1'; | ||
23 | - this.hero = { id: 1, name: 'Anderson' }; | ||
24 | - } | ||
25 | - AppComponent.prototype.ngOnInit = function () { | ||
26 | - this.getHeroes(); | ||
27 | - }; | ||
28 | - AppComponent.prototype.getHeroes = function () { | ||
29 | - // this.heroService.getHeroes().then(heroes => this.heroes = heroes); | ||
30 | - var _this = this; | ||
31 | - //Simulate server latency | ||
32 | - // this.heroService.getHeroesSlowly().then(heroes => this.heroes = heroes); | ||
33 | - this.heroService.getHeroes().then(function (heroes) { return _this.heroes = heroes; }); | ||
34 | - }; | ||
35 | - AppComponent.prototype.onSelect = function (hero) { | ||
36 | - this.selectedHero = hero; | ||
37 | - // alert(this.selectedHero.name); | ||
38 | - }; | ||
39 | - return AppComponent; | ||
40 | -}()); | ||
41 | -AppComponent = __decorate([ | ||
42 | - core_1.Component({ | ||
43 | - selector: 'my-app', | ||
44 | - // template: `<h1>Hello1 {{name}}</h1>`, | ||
45 | - templateUrl: 'app/app.component.html', | ||
46 | - styleUrls: ['app/app.component.css'], | ||
47 | - providers: [hero_service_1.HeroService] | ||
48 | - }), | ||
49 | - __metadata("design:paramtypes", [hero_service_1.HeroService]) | ||
50 | -], AppComponent); | ||
51 | -exports.AppComponent = AppComponent; | ||
52 | -//# sourceMappingURL=app.component.js.map |
src/app/app.component.js.map
deleted
100644 → 0
1 | -{"version":3,"file":"app.component.js","sourceRoot":"","sources":["app.component.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,sCAAiD;AAEjD,wDAAmD;AAYnD,IAAa,YAAY;IAazB,mDAAmD;IACnD,+CAA+C;IAE/C,sCAAsC;IACtC,+EAA+E;IAC/E,MAAM;IAEN,aAAa;IACX,sBAAoB,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;QApB5C,SAAI,GAAG,UAAU,CAAC;QAClB,SAAI,GAAQ,EAAC,EAAE,EAAC,CAAC,EAAE,IAAI,EAAC,UAAU,EAAC,CAAC;IAoBpC,CAAC;IAED,+BAAQ,GAAR;QACG,IAAI,CAAC,SAAS,EAAE,CAAC;IACpB,CAAC;IACF,gCAAS,GAAT;QACG,qEAAqE;QADxE,iBAOE;QAJC,yBAAyB;QACzB,2EAA2E;QAE3E,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,KAAI,CAAC,MAAM,GAAG,MAAM,EAApB,CAAoB,CAAC,CAAC;IACpE,CAAC;IAGD,+BAAQ,GAAR,UAAS,IAAU;QACjB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,iCAAiC;IACnC,CAAC;IACH,mBAAC;AAAD,CAAC,AAzCD,IAyCC;AAzCY,YAAY;IARxB,gBAAS,CAAC;QACT,QAAQ,EAAE,QAAQ;QAClB,wCAAwC;QACxC,WAAW,EAAE,wBAAwB;QAErC,SAAS,EAAC,CAAC,uBAAuB,CAAC;QAClC,SAAS,EAAE,CAAC,0BAAW,CAAC;KAC1B,CAAC;qCAsBiC,0BAAW;GArBjC,YAAY,CAyCxB;AAzCY,oCAAY"} |
1 | import { Component,OnInit } from '@angular/core'; | 1 | import { Component,OnInit } from '@angular/core'; |
2 | import {Hero} from './models/hero' | 2 | import {Hero} from './models/hero' |
3 | import {HeroService} from './services/hero.service' | 3 | import {HeroService} from './services/hero.service' |
4 | +import {TokenService} from './services/token.service' | ||
5 | + | ||
4 | import { HttpModule } from '@angular/http'; | 6 | import { HttpModule } from '@angular/http'; |
5 | 7 | ||
6 | 8 | ||
@@ -10,7 +12,7 @@ import { HttpModule } from '@angular/http'; | @@ -10,7 +12,7 @@ import { HttpModule } from '@angular/http'; | ||
10 | templateUrl: 'app/app.component.html', | 12 | templateUrl: 'app/app.component.html', |
11 | 13 | ||
12 | styleUrls:['app/app.component.css'], | 14 | styleUrls:['app/app.component.css'], |
13 | - providers: [HeroService] | 15 | + providers: [HeroService,TokenService] |
14 | }) | 16 | }) |
15 | export class AppComponent { | 17 | export class AppComponent { |
16 | name = 'Angular1'; | 18 | name = 'Angular1'; |
@@ -33,7 +35,7 @@ export class AppComponent { | @@ -33,7 +35,7 @@ export class AppComponent { | ||
33 | // } | 35 | // } |
34 | 36 | ||
35 | // //ngOnInit | 37 | // //ngOnInit |
36 | - constructor(private heroService: HeroService) { | 38 | + constructor(private heroService: HeroService, private tokenService: TokenService) { |
37 | } | 39 | } |
38 | 40 | ||
39 | ngOnInit(): void { | 41 | ngOnInit(): void { |
@@ -46,6 +48,8 @@ export class AppComponent { | @@ -46,6 +48,8 @@ export class AppComponent { | ||
46 | // this.heroService.getHeroesSlowly().then(heroes => this.heroes = heroes); | 48 | // this.heroService.getHeroesSlowly().then(heroes => this.heroes = heroes); |
47 | 49 | ||
48 | this.heroService.getHeroes().then(heroes => this.heroes = heroes); | 50 | this.heroService.getHeroes().then(heroes => this.heroes = heroes); |
51 | + //token service call | ||
52 | + // this.tokenService.token().then(t=> alert('Auth pass')); | ||
49 | } | 53 | } |
50 | // Event Handling | 54 | // Event Handling |
51 | selectedHero: Hero; | 55 | selectedHero: Hero; |
src/app/app.module.js
deleted
100644 → 0
1 | -"use strict"; | ||
2 | -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
3 | - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
4 | - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
5 | - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
6 | - return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
7 | -}; | ||
8 | -var core_1 = require("@angular/core"); | ||
9 | -var platform_browser_1 = require("@angular/platform-browser"); | ||
10 | -var forms_1 = require("@angular/forms"); | ||
11 | -//Http Service | ||
12 | -var http_1 = require("@angular/http"); | ||
13 | -var app_component_1 = require("./app.component"); | ||
14 | -var hero_detail_component_1 = require("./hero-detail/hero-detail.component"); | ||
15 | -// Imports for loading & configuring the in-memory web api | ||
16 | -var angular_in_memory_web_api_1 = require("angular-in-memory-web-api"); | ||
17 | -var in_memory_data_service_1 = require("./services/mocks/in-memory-data.service"); | ||
18 | -var AppModule = (function () { | ||
19 | - function AppModule() { | ||
20 | - } | ||
21 | - return AppModule; | ||
22 | -}()); | ||
23 | -AppModule = __decorate([ | ||
24 | - core_1.NgModule({ | ||
25 | - imports: [platform_browser_1.BrowserModule, | ||
26 | - //Http Service | ||
27 | - http_1.HttpModule, | ||
28 | - forms_1.FormsModule, | ||
29 | - angular_in_memory_web_api_1.InMemoryWebApiModule.forRoot(in_memory_data_service_1.InMemoryDataService)], | ||
30 | - declarations: [app_component_1.AppComponent, | ||
31 | - hero_detail_component_1.HeroDetailComponent], | ||
32 | - bootstrap: [app_component_1.AppComponent] | ||
33 | - }) | ||
34 | -], AppModule); | ||
35 | -exports.AppModule = AppModule; | ||
36 | -//# sourceMappingURL=app.module.js.map |
src/app/app.module.js.map
deleted
100644 → 0
1 | -{"version":3,"file":"app.module.js","sourceRoot":"","sources":["app.module.ts"],"names":[],"mappings":";;;;;;;AAAA,sCAA8C;AAC9C,8DAA0D;AAC1D,wCAA6C;AAE7C,cAAc;AACd,sCAA8C;AAE9C,iDAAgD;AAChD,6EAA2E;AAE3E,0DAA0D;AAC1D,uEAAiE;AACjE,kFAA+E;AAa/E,IAAa,SAAS;IAAtB;IAAyB,CAAC;IAAD,gBAAC;AAAD,CAAC,AAA1B,IAA0B;AAAb,SAAS;IAXrB,eAAQ,CAAC;QACR,OAAO,EAAO,CAAE,gCAAa;YAC7B,cAAc;YACd,iBAAU;YACV,mBAAW;YACX,gDAAoB,CAAC,OAAO,CAAC,4CAAmB,CAAC,CAAC;QAClD,YAAY,EAAE,CAAE,4BAAY;YACtB,2CAAmB,CAAE;QAC3B,SAAS,EAAK,CAAE,4BAAY,CAAE;KAE/B,CAAC;GACW,SAAS,CAAI;AAAb,8BAAS"} |
@@ -12,12 +12,23 @@ import { HeroDetailComponent } from './hero-detail/hero-detail.component'; | @@ -12,12 +12,23 @@ import { HeroDetailComponent } from './hero-detail/hero-detail.component'; | ||
12 | import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; | 12 | import { InMemoryWebApiModule } from 'angular-in-memory-web-api'; |
13 | import { InMemoryDataService } from './services/mocks/in-memory-data.service'; | 13 | import { InMemoryDataService } from './services/mocks/in-memory-data.service'; |
14 | 14 | ||
15 | +//Routing | ||
16 | +import { RouterModule } from '@angular/router'; | ||
17 | + | ||
15 | @NgModule({ | 18 | @NgModule({ |
16 | imports: [ BrowserModule , | 19 | imports: [ BrowserModule , |
17 | //Http Service | 20 | //Http Service |
18 | HttpModule, | 21 | HttpModule, |
19 | FormsModule, | 22 | FormsModule, |
20 | - InMemoryWebApiModule.forRoot(InMemoryDataService)], | 23 | + RouterModule.forRoot([ |
24 | + { path: 'home', component: AppComponent}, | ||
25 | + // { path: 'detail', component: HeroDetailComponent} , | ||
26 | + { path: 'detail/:id', component: HeroDetailComponent} //Parameterized route | ||
27 | + ]), | ||
28 | + InMemoryWebApiModule.forRoot( | ||
29 | + InMemoryDataService | ||
30 | + ,{ passThruUnknownUrl: true} //this will use the normal XHRBackend if the collection in the mock data can't be found | ||
31 | + )], | ||
21 | declarations: [ AppComponent, | 32 | declarations: [ AppComponent, |
22 | HeroDetailComponent ], | 33 | HeroDetailComponent ], |
23 | bootstrap: [ AppComponent ] | 34 | bootstrap: [ AppComponent ] |
1 | -"use strict"; | ||
2 | -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
3 | - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
4 | - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
5 | - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
6 | - return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
7 | -}; | ||
8 | -var __metadata = (this && this.__metadata) || function (k, v) { | ||
9 | - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
10 | -}; | ||
11 | -var core_1 = require("@angular/core"); | ||
12 | -var hero_1 = require("../models/hero"); | ||
13 | -var HeroDetailComponent = (function () { | ||
14 | - function HeroDetailComponent() { | ||
15 | - } | ||
16 | - return HeroDetailComponent; | ||
17 | -}()); | ||
18 | -__decorate([ | ||
19 | - core_1.Input(), | ||
20 | - __metadata("design:type", hero_1.Hero) | ||
21 | -], HeroDetailComponent.prototype, "hero", void 0); | ||
22 | -HeroDetailComponent = __decorate([ | ||
23 | - core_1.Component({ | ||
24 | - selector: 'hero-detail', | ||
25 | - // template: ` | ||
26 | - // <div *ngIf="hero"> | ||
27 | - // <h2>{{hero.name}} details!</h2> | ||
28 | - // <div><label>id: </label>{{hero.id}}</div> | ||
29 | - // <div> | ||
30 | - // <label>name: </label> | ||
31 | - // <input [(ngModel)]="hero.name" placeholder="name"/> | ||
32 | - // </div> | ||
33 | - // </div> | ||
34 | - // `, | ||
35 | - templateUrl: './hero-detail.component.html', | ||
36 | - styleUrls: ['./hero-detail.component.css'] | ||
37 | - }) | ||
38 | -], HeroDetailComponent); | ||
39 | -exports.HeroDetailComponent = HeroDetailComponent; | ||
40 | -//# sourceMappingURL=hero-detail.component.js.map |
1 | -{"version":3,"file":"hero-detail.component.js","sourceRoot":"","sources":["hero-detail.component.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,sCAAgD;AAChD,uCAAqC;AAkBrC,IAAa,mBAAmB;IAAhC;IAEC,CAAC;IAAD,0BAAC;AAAD,CAAC,AAFF,IAEE;AADS;IAAR,YAAK,EAAE;8BAAO,WAAI;iDAAC;AADT,mBAAmB;IAhB/B,gBAAS,CAAC;QACT,QAAQ,EAAE,aAAa;QACzB,gBAAgB;QAChB,yBAAyB;QACzB,wCAAwC;QACxC,kDAAkD;QAClD,cAAc;QACd,gCAAgC;QAChC,8DAA8D;QAC9D,eAAe;QACf,aAAa;QACb,OAAO;QACJ,WAAW,EAAC,8BAA8B;QAE3C,SAAS,EAAC,CAAC,6BAA6B,CAAC;KAC1C,CAAC;GACW,mBAAmB,CAE9B;AAFW,kDAAmB"} |
1 | import { Component,Input } from '@angular/core'; | 1 | import { Component,Input } from '@angular/core'; |
2 | import {Hero } from '../models/hero'; | 2 | import {Hero } from '../models/hero'; |
3 | 3 | ||
4 | +import { Location } from '@angular/common'; | ||
5 | +import { ActivatedRoute, Params } from '@angular/router'; | ||
6 | + | ||
7 | +//ngOnInit | ||
8 | +import { OnInit } from '@angular/core'; | ||
9 | + | ||
10 | +import 'rxjs/add/operator/switchMap'; | ||
11 | + | ||
12 | +import { HeroService } from '../services/hero.service'; | ||
13 | + | ||
4 | @Component({ | 14 | @Component({ |
5 | selector: 'hero-detail', | 15 | selector: 'hero-detail', |
6 | -// template: ` | ||
7 | -// <div *ngIf="hero"> | ||
8 | -// <h2>{{hero.name}} details!</h2> | ||
9 | -// <div><label>id: </label>{{hero.id}}</div> | ||
10 | -// <div> | ||
11 | -// <label>name: </label> | ||
12 | -// <input [(ngModel)]="hero.name" placeholder="name"/> | ||
13 | -// </div> | ||
14 | -// </div> | ||
15 | -// `, | 16 | + // template: ` |
17 | + // <div *ngIf="hero"> | ||
18 | + // <h2>{{hero.name}} details!</h2> | ||
19 | + // <div><label>id: </label>{{hero.id}}</div> | ||
20 | + // <div> | ||
21 | + // <label>name: </label> | ||
22 | + // <input [(ngModel)]="hero.name" placeholder="name"/> | ||
23 | + // </div> | ||
24 | + // </div> | ||
25 | + // ` | ||
16 | templateUrl:'./hero-detail.component.html', | 26 | templateUrl:'./hero-detail.component.html', |
17 | 27 | ||
18 | styleUrls:['./hero-detail.component.css'] | 28 | styleUrls:['./hero-detail.component.css'] |
19 | }) | 29 | }) |
20 | -export class HeroDetailComponent { | 30 | +export class HeroDetailComponent implements OnInit { |
21 | @Input() hero: Hero; | 31 | @Input() hero: Hero; |
32 | + | ||
33 | + constructor( | ||
34 | + private route: ActivatedRoute, | ||
35 | + private location: Location, | ||
36 | + private heroService: HeroService | ||
37 | + ) {} | ||
38 | + | ||
39 | +ngOnInit(): void { | ||
40 | + this.route.params | ||
41 | + .switchMap((params: Params) => this.heroService.getHero(+params['id'])) | ||
42 | + .subscribe(hero => this.hero = hero); | ||
43 | +} | ||
44 | + goBack(): void { | ||
45 | + this.location.back(); | ||
46 | +} | ||
22 | } | 47 | } |
1 | -//# sourceMappingURL=hero-detail.component.js.map |
1 | -{"version":3,"file":"hero-detail.component.js","sourceRoot":"","sources":["hero-detail.component.ts"],"names":[],"mappings":""} |
src/app/models/hero.js
deleted
100644 → 0
src/app/models/hero.js.map
deleted
100644 → 0
1 | -{"version":3,"file":"hero.js","sourceRoot":"","sources":["hero.ts"],"names":[],"mappings":";AAAA;IAAA;IAGA,CAAC;IAAD,WAAC;AAAD,CAAC,AAHD,IAGC;AAHY,oBAAI"} |
src/app/services/hero.service.js
deleted
100644 → 0
1 | -"use strict"; | ||
2 | -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
3 | - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
4 | - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
5 | - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
6 | - return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
7 | -}; | ||
8 | -var __metadata = (this && this.__metadata) || function (k, v) { | ||
9 | - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
10 | -}; | ||
11 | -var core_1 = require("@angular/core"); | ||
12 | -//HTTP Service | ||
13 | -var http_1 = require("@angular/http"); | ||
14 | -require("rxjs/add/operator/toPromise"); | ||
15 | -// @Injectable() | ||
16 | -// export class HeroService { | ||
17 | -// getHeroes(): Hero[] { | ||
18 | -// return HEROES; | ||
19 | -// } | ||
20 | -// } | ||
21 | -// Async services and Promises | ||
22 | -var HeroService = (function () { | ||
23 | - function HeroService(http) { | ||
24 | - this.http = http; | ||
25 | - // getHeroes(): Promise<Hero[]> { | ||
26 | - // return Promise.resolve(HEROES); | ||
27 | - // } | ||
28 | - // getHeroesSlowly(): Promise<Hero[]> { | ||
29 | - // return new Promise(resolve => { | ||
30 | - // // Simulate server latency with 2 second delay | ||
31 | - // setTimeout(() => resolve(this.getHeroes()), 2000); | ||
32 | - // }); | ||
33 | - // } | ||
34 | - //HTTP service | ||
35 | - // private heroesUrl = './mocks/in-memory-data.service'; // URL to web api | ||
36 | - this.heroesUrl = 'api/heroes'; // URL to web api | ||
37 | - } | ||
38 | - HeroService.prototype.getHeroes = function () { | ||
39 | - return this.http.get(this.heroesUrl) | ||
40 | - .toPromise() | ||
41 | - .then(function (response) { return response.json().data; }) | ||
42 | - .catch(this.handleError); | ||
43 | - }; | ||
44 | - HeroService.prototype.handleError = function (error) { | ||
45 | - console.error('An error occurred', error); // for demo purposes only | ||
46 | - return Promise.reject(error.message || error); | ||
47 | - }; | ||
48 | - return HeroService; | ||
49 | -}()); | ||
50 | -HeroService = __decorate([ | ||
51 | - core_1.Injectable(), | ||
52 | - __metadata("design:paramtypes", [http_1.Http]) | ||
53 | -], HeroService); | ||
54 | -exports.HeroService = HeroService; | ||
55 | -//# sourceMappingURL=hero.service.js.map |
src/app/services/hero.service.js.map
deleted
100644 → 0
1 | -{"version":3,"file":"hero.service.js","sourceRoot":"","sources":["hero.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,sCAA2C;AAE3C,cAAc;AACd,sCAA8C;AAC9C,uCAAqC;AAKrC,gBAAgB;AAChB,6BAA6B;AAC7B,0BAA0B;AAC1B,qBAAqB;AACrB,MAAM;AACN,IAAI;AAEJ,+BAA+B;AAE/B,IAAa,WAAW;IAetB,qBAAoB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAdhC,mCAAmC;QACnC,sCAAsC;QACtC,MAAM;QAEN,yCAAyC;QACzC,oCAAoC;QACpC,qDAAqD;QACrD,yDAAyD;QACzD,QAAQ;QACR,IAAI;QAEJ,cAAc;QACd,2EAA2E;QACnE,cAAS,GAAG,YAAY,CAAC,CAAE,iBAAiB;IAChB,CAAC;IACnC,+BAAS,GAAT;QACE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;aACxB,SAAS,EAAE;aACX,IAAI,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAc,EAA9B,CAA8B,CAAC;aAChD,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IACO,iCAAW,GAAnB,UAAoB,KAAU;QAC5B,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,yBAAyB;QACpE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;IAChD,CAAC;IACH,kBAAC;AAAD,CAAC,AA1BD,IA0BC;AA1BY,WAAW;IADvB,iBAAU,EAAE;qCAgBe,WAAI;GAfnB,WAAW,CA0BvB;AA1BY,kCAAW"} |
@@ -38,6 +38,12 @@ private heroesUrl = 'api/heroes'; // URL to web api | @@ -38,6 +38,12 @@ private heroesUrl = 'api/heroes'; // URL to web api | ||
38 | .then(response => response.json().data as Hero[]) | 38 | .then(response => response.json().data as Hero[]) |
39 | .catch(this.handleError); | 39 | .catch(this.handleError); |
40 | } | 40 | } |
41 | + | ||
42 | + getHero(id: number): Promise<Hero> { | ||
43 | + return this.getHeroes() | ||
44 | + .then(heroes => heroes.find(hero => hero.id === id)); | ||
45 | + } | ||
46 | + | ||
41 | private handleError(error: any): Promise<any> { | 47 | private handleError(error: any): Promise<any> { |
42 | console.error('An error occurred', error); // for demo purposes only | 48 | console.error('An error occurred', error); // for demo purposes only |
43 | return Promise.reject(error.message || error); | 49 | return Promise.reject(error.message || error); |
1 | -"use strict"; | ||
2 | -var InMemoryDataService = (function () { | ||
3 | - function InMemoryDataService() { | ||
4 | - } | ||
5 | - InMemoryDataService.prototype.createDb = function () { | ||
6 | - var heroes = [ | ||
7 | - { id: 11, name: 'Mr. Nice' }, | ||
8 | - { id: 12, name: 'Narco' }, | ||
9 | - { id: 13, name: 'Bombasto' }, | ||
10 | - { id: 14, name: 'Celeritas' }, | ||
11 | - { id: 15, name: 'Magneta' }, | ||
12 | - { id: 16, name: 'RubberMan' }, | ||
13 | - { id: 17, name: 'Dynama' }, | ||
14 | - { id: 18, name: 'Dr IQ' }, | ||
15 | - { id: 19, name: 'Magma' }, | ||
16 | - { id: 20, name: 'Tornado' } | ||
17 | - ]; | ||
18 | - return { heroes: heroes }; | ||
19 | - }; | ||
20 | - return InMemoryDataService; | ||
21 | -}()); | ||
22 | -exports.InMemoryDataService = InMemoryDataService; | ||
23 | -//# sourceMappingURL=in-memory-data.service.js.map |
1 | -{"version":3,"file":"in-memory-data.service.js","sourceRoot":"","sources":["in-memory-data.service.ts"],"names":[],"mappings":";AACA;IAAA;IAgBA,CAAC;IAfC,sCAAQ,GAAR;QACE,IAAI,MAAM,GAAG;YACX,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAC;YAC1B,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAC;YACvB,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAC;YAC1B,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAC;YAC3B,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAC;YACzB,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAC;YAC3B,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAC;YACxB,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAC;YACvB,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAC;YACvB,EAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAC;SAC1B,CAAC;QACF,MAAM,CAAC,EAAC,MAAM,QAAA,EAAC,CAAC;IAClB,CAAC;IACH,0BAAC;AAAD,CAAC,AAhBD,IAgBC;AAhBY,kDAAmB"} |
@@ -13,6 +13,8 @@ export class InMemoryDataService implements InMemoryDbService { | @@ -13,6 +13,8 @@ export class InMemoryDataService implements InMemoryDbService { | ||
13 | {id: 19, name: 'Magma'}, | 13 | {id: 19, name: 'Magma'}, |
14 | {id: 20, name: 'Tornado'} | 14 | {id: 20, name: 'Tornado'} |
15 | ]; | 15 | ]; |
16 | + // let user=[{id:1, email:'a@a.com'}]; | ||
17 | + | ||
16 | return {heroes}; | 18 | return {heroes}; |
17 | } | 19 | } |
18 | } | 20 | } |
1 | -"use strict"; | ||
2 | -exports.HEROES = [ | ||
3 | - { id: 11, name: 'Mr. Nicest' }, | ||
4 | - { id: 12, name: 'Narco' }, | ||
5 | - { id: 13, name: 'Bombasto' }, | ||
6 | - { id: 14, name: 'Celeritas' }, | ||
7 | - { id: 15, name: 'Magneta' }, | ||
8 | - { id: 16, name: 'RubberMan' }, | ||
9 | - { id: 17, name: 'Dynama' }, | ||
10 | - { id: 18, name: 'Dr IQ' }, | ||
11 | - { id: 19, name: 'Magma' }, | ||
12 | - { id: 20, name: 'Tornado' } | ||
13 | -]; | ||
14 | -//# sourceMappingURL=mock-heroes.js.map |
1 | -{"version":3,"file":"mock-heroes.js","sourceRoot":"","sources":["mock-heroes.ts"],"names":[],"mappings":";AAEa,QAAA,MAAM,GAAW;IAC5B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE;IAC9B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;IACzB,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;IAC5B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;IAC7B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;IAC3B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;IAC7B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC1B,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;IACzB,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;IACzB,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;CAC5B,CAAC"} |
src/app/services/token.service.ts
0 → 100644
1 | +import { Injectable } from '@angular/core'; | ||
2 | + | ||
3 | +//HTTP Service | ||
4 | +import { Headers, Http } from '@angular/http'; | ||
5 | +import 'rxjs/add/operator/toPromise'; | ||
6 | + | ||
7 | +import { Hero } from '../models/hero'; | ||
8 | +import { HEROES } from './mocks/mock-heroes'; | ||
9 | + | ||
10 | +// @Injectable() | ||
11 | +// export class HeroService { | ||
12 | +// getHeroes(): Hero[] { | ||
13 | +// return HEROES; | ||
14 | +// } | ||
15 | +// } | ||
16 | + | ||
17 | +// Async services and Promises | ||
18 | +@Injectable() | ||
19 | +export class TokenService { | ||
20 | +// getHeroes(): Promise<Hero[]> { | ||
21 | +// return Promise.resolve(HEROES); | ||
22 | +// } | ||
23 | + | ||
24 | +// getHeroesSlowly(): Promise<Hero[]> { | ||
25 | +// return new Promise(resolve => { | ||
26 | +// // Simulate server latency with 2 second delay | ||
27 | +// setTimeout(() => resolve(this.getHeroes()), 2000); | ||
28 | +// }); | ||
29 | +// } | ||
30 | + | ||
31 | +//HTTP service | ||
32 | +// private heroesUrl = './mocks/in-memory-data.service'; // URL to web api | ||
33 | + constructor(private http: Http) { } | ||
34 | + private tokenUrl = 'http://uatb2bservices.crimsoni.com/csapis/token'; // URL to web api | ||
35 | + private headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }); | ||
36 | + | ||
37 | + token(): Promise<string> { | ||
38 | + return this.http | ||
39 | + .post(this.tokenUrl, 'Password=123456&grant_type=password&UserName=b8a9df77-9d3d-4574-96a1-1baae377257b', { headers: this.headers }) | ||
40 | + .toPromise() | ||
41 | + .then(res => res.json().data as string) | ||
42 | + .catch(this.handleError); | ||
43 | + } | ||
44 | + | ||
45 | + private handleError(error: any): Promise<any> { | ||
46 | + console.error('An error occurred', error); // for demo purposes only | ||
47 | + return Promise.reject(error.message || error); | ||
48 | + } | ||
49 | +} | ||
50 | + |
src/main.js.map
deleted
100644 → 0
1 | -{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";AAAA,8EAA2E;AAE3E,+CAA6C;AAE7C,iDAAsB,EAAE,CAAC,eAAe,CAAC,sBAAS,CAAC,CAAC"} |
-
Please register or login to post a comment