text: "use strict";
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      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;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  var __metadata = (this && this.__metadata) || function (k, v) {
      if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  };
  var core_1 = require('@angular/core');
  var http_1 = require('@angular/http');
  var HeroService = (function () {
      function HeroService(http) {
          this.http = http;
          this.heroesUrl = 'api/heroes';
          this.headers = new http_1.Headers({ 'Content-Type': 'application/json' });
      }
      HeroService.prototype.getHero = function (id) {
          // return this.getHeroes()
          // 		.then(heroes => heroes.find(hero => hero.id === id));
          var url = this.heroesUrl + "/" + id;
          return this.http.get(url)
              .toPromise()
              .then(function (response) { return response.json().data; })
              .catch(this.handleError);
      };
      HeroService.prototype.getHeroes = function () {
          return this.http
              .get(this.heroesUrl)
              .map(function (r) { return r.json().data; })
              .catch(this.handleError);
          // return this.http.get(this.heroesUrl)
          // 	.toPromise()
          // 	.then(response => response.json().data as Hero[])
          // 	.catch(this.handleError);
      };
      HeroService.prototype.create = function (name) {
          return this.http
              .post(this.heroesUrl, JSON.stringify({ name: name }), { headers: this.headers })
              .map(function (res) { return res.json().data; })
              .catch(this.handleError);
          // return this.http
          // 	.post(this.heroesUrl, JSON.stringify({name: name}), {headers: this.headers})
          // 	.toPromise()
          // 	.then(res => res.json().data)
          // 	.catch(this.handleError)
      };
      HeroService.prototype.handleError = function (error) {
          console.error('An error occurred', error); //for demo
          return Promise.reject(error.message || error);
      };
      HeroService = __decorate([
          core_1.Injectable(), 
          __metadata('design:paramtypes', [http_1.Http])
      ], HeroService);
      return HeroService;
  }());
  exports.HeroService = HeroService;
  //# sourceMappingURL=hero.service.js.map