When you use the Angular CLI to create a component, it will automatically create a selector, templateUrl and styleUrl for you.
The templateURL will be set to the component HTML template. You can pass information back and forth between your template and component class.
Ways to Use a Component
There are several ways a component can be used…
- As the root component
- As a child component…inside another component
- Navigation…you can display a component by navigating to it and it will display in the RouterOutlet element
- By dynamically loading it with the ComponentFactoryResolver
The first three are the most common. The component must be a part of an Angular module. To do this, you import the component and pass it to the declarations array.
...
import { SomeComponent } from '../some.component';
...
@NgModule( {
declarations: [
SomeComponent
]
...
} )
export class MyModule { }
Happy Coding!
Clay Hess