Practices - Do you know to separate your Angular components into container and presentational components?
  v4.0 Posted at 23/12/2019 5:27 PM by Gabriel George

​​​​There are two types of components 'dumb' and 'smart' components. Dumb components normally have no dependencies and no logic and just have @Input() and @Output(). Smart components are their parent components that would have multiple dependencies and logic but not necessarily an HTML template.​

​​Aiming to keep the components that display data 'dumb' makes them much easy to reuse in your application and less buggy, but many people do not like the terms smart and dumb components as a dumb component may just have less logic versus none. Many people and SSW included are preferring the terms container and presentational components for these reasons.​​​

    selector: 'fbc-company-list-table',
    template: `
     <table id="company-list-table" class="table table-hover table-striped company-list-table-component">
               <tr class="item" *ngFor="let company of companies">
                    <td class="button-column">
                        <button routerLink="/company/detail/{{company.id}}" class="btn btn-default" >Details</button>
                        <button routerLink="/company/edit/{{company.id}}" class="btn btn-default" >Edit</button>
                        <button (click)="confirmDelete(company)" class="btn btn-default">Delete</button>
export class CompanyListTableComponent {
    @Input() companies: Company[];
    @Output() deleteCompanySelected = new EventEmitter<number>();
    confirmDelete(company: Company) {

​Figure: Good example of a presenta​​tional component with no injected dependencies​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: