Angular 2 - Component Creation (Tags)

Asked

Viewed 522 times

0

How do I create components in Angular? I want my team to put an Ex TAG:

<campoBusca></campoBusca>

and on the screen is already printed a input all straight, with the Divs necessary, etc! gave to understand? It is the same principle of the component of JSF!

1 answer

0


1-Create a component (field-search.component.ts)

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

@Component({

  selector: 'my-campo-busca',

  templateUrl: './campo-busca.component.html',

  styleUrls: ['./campo-busca.component.css']

})

export class CampoBuscaComponent {

  constructor() { }

}

2-Define component html (field-search.component.html)

<input type="text"... 

3- Declare the component in the application module (app.module.ts)

import { CampoBuscaComponent } from 'campo-busca.component.ts';

@NgModule({
  declarations: [ CampoBuscaComponent ]
})

4-Use in html:

<my-campo-busca></my-campo-busca>

Good practice is to use the prefix my to distinguish between native and angular components.

Worth a look at convention of nomenclature and height of the angular

*I have a code at angle 4 on the github that I use with angular cli.

If you want you can clone and parse the code. You only need to install angular cli first with the command:

npm install @angular/cli -g

And then ng serve --open to open

https://github.com/Marcelo-Rodrigues/ng-architect

Browser other questions tagged

You are not signed in. Login or sign up in order to post.