1
resposta

Erro GET http://localhost:4200/null 404 (Not Found)

Recebo o erro "Erro GET http://localhost:4200/null 404 (Not Found)" ao gerar o component ap-photo. (Não é a url que eu acesso, é o erro que aparece no console)

photo.component.html

<img class="img-thumbnail" [src]="url" [alt]="description">

photo.component.ts

import { Component } from '@angular/core';

@Component({
    selector: 'ap-photo',
    templateUrl: 'photo.component.html'
})
export class PhotoComponent {
    description: 'Leão';
    url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Sultan_the_Barbary_Lion.jpg/440px-Sultan_the_Barbary_Lion.jpg';
}

app.modules.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { PhotoComponent } from './photo/photo.component';

@NgModule({
  declarations: [
    AppComponent,
    PhotoComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

<ap-photo></ap-photo>
1 resposta

Olá Andre,

No teu arquivo photo.component.ts troque

 templateUrl: 'photo.component.html' 

por

 templateUrl: './photo.component.html'

O erro é a falta do ./ que indica o diretório corrente.