To create a component we add @Component
decorator in a class passing some parameters:
providers
: Resources that will be injected into the component constructorselector
: The query selector that will find the element in the HTML and replace by the componentstyles
: Inline styles. NOTE: DO NOT use this parameter with require, it works on development but when you build the application in production all your styles are loststyleUrls
: Array of path to style filestemplate
: String that contains your HTMLtemplateUrl
: Path to a HTML fileThere are other parameters you can configure, but the listed ones are what you will use the most.
A simple example:
import { Component } from '@angular/core';
@Component({
selector: 'app-required',
styleUrls: ['required.component.scss'],
// template: `This field is required.`,
templateUrl: 'required.component.html',
})
export class RequiredComponent { }