Segue meu código:
Componente
import { Component, OnInit, Input } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'foto',
templateUrl: './foto.component.html',
styleUrls: ['./foto.component.css']
})
export class FotoComponent implements OnInit {
@Input() titulo;
@Input() url;
constructor() { }
ngOnInit() {
}
}
Modulo
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FotoComponent } from './foto.component';
@NgModule({
imports: [
CommonModule
],
declarations: [
FotoComponent
],
exports: [
FotoComponent
]
})
export class FotoModule { }
Template
<img class="img-responsive center-block" src="{{url}}}" alt="{{titulo}}">
AppModule
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { MeuPrimeiroModule } from './meu-primeiro/meu-primeiro.module';
import { FotoModule } from './foto/foto.module';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
MeuPrimeiroModule,
FotoModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
AppComponent
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}
AppComponent.html
<foto url="img/leao.jpg" titulo="Leão" ></foto>