Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Problema com criação de serviço

Estou recebendo o seguinte erro no console ao rodar o 'ng server':

ERROR in /home/vicio/Desenvolvimento/eSports-team/Front/src/app/usuario/usuario.component.service.ts (2,30): Unterminated string literal.

ERROR in /home/vicio/Desenvolvimento/eSports-team/Front/src/app/usuario/usuario.component.service.ts (2,27): Cannot find module '.t'.

ERROR in /home/vicio/Desenvolvimento/eSports-team/Front/src/app/usuario/usuario.component.service.ts (19,26): Cannot find name 'CadastroUsuarioComponent'.

Procurei por 'spring', '.t', e 'CadastroUsuarioComponent' no meu service mas não encontrei, o erro não esta fazendo muito sentido.

import { Http, Headers, Response } from '@angular/http';
import { UsuarioComponent } from './usuario.component';
import 'rxjs/add/operator/toPromise';
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';

@Injectable()
export class UsuarioService { 

    http: Http;
    headers: Headers;
    url: string = 'http://localhost:3000/v1/usuarios';

    constructor(http: Http) {
        this.http = http;
        this.headers = new Headers();
        this.headers.append('Content-Type', 'application/json');
  }

  lista(): Promise<UsuarioComponent[]>{
      return this.http.get(this.url)
        .toPromise()
        .then(res => res.json())
        .catch();
  }

  cadastrar(usuario: UsuarioComponent): Promise<any> {
      if(usuario._id){
          return this.http.put(this.url + '/' + usuario._id, JSON.stringify(usuario),
            { headers: this.headers })
            .toPromise()
                .then(res => res.json())
                .catch();
      } else {
          return this.http.post(this.url, JSON.stringify(usuario),
          { headers: this.headers })
          .toPromise()
            .then(res => res.json())
            .catch();
      }
  }

  remove(usuario: UsuarioComponent): Observable<Response> {
      return this.http.delete(this.url + '/' + usuario._id);
  }

  buscarPorId(id: string): Observable<UsuarioComponent> {
     return this.http
      .get(this.url + '/' + id)
      .map(res => res.json());
    }

}
2 respostas
solução!

Da uma olhada na linha indicada aqui

ERROR in /home/vicio/Desenvolvimento/eSports-team/Front/src/app/usuario/usuario.component.service.ts (2,30): Unterminated string literal.

Há um erro de sintaxe indicado. Talvez ele seja a causa de todos os demais erros.

Verifiquei, era um nome declarado errado.

Obrigado!