19 CEO Dashboard Examples for Business Leaders
Let's rewind to the 1990s. Data used to be stored on servers and CEOs relied on basic tools to make optimal decisions. No dashboards, nothing. When you use Power BI with a solid...
Kapil Panchal - June 25, 2021
Listening is fun too.
Straighten your back and cherish with coffee - PLAY !
Angular was designed to advance code reusability. Angular Reusable components are those react components that can be used multiple times in your application. As a result, they need to be generic enough so that it’s free from complex business logic.
One of the ways is to pass inputs and specified data to the component to render and configure the component.
Another way is, use content projection to pass a template to the reusable component.
Presentation Components
Coding angular reusable components is not only a best practice, but it’s actually practical and can cause you to more efficient. How?? See the below example for that.
Well, when creating a component, we often end up with a situation as this one:
import { Component } from '@angular/core'; @Component({ selector: 'app-page', templateUrl: './page.component.html', styleUrls: ['./page.component.css'] }) class Page { title: string; actions: []; diplayFilters: boolean; displaySearch: boolean; displaySort: boolean; displayPagination: boolean; dataset: []; canEditRow: boolean; canDeleteRow: boolean; } export class pagecomponent{ }
This component used in the app.component.html in this way.
In that kind of problem, we end up with a component that is very hard to extend in parameters. So let’s discuss how to improve this kind of problem.
Angular comes with multiple ways to inject content within the DOM. The first is content projection, and here is the example of it:
import { Component } from '@angular/core'; @Component({ selector: 'app-page-list', templateUrl: '' }) class PageList{ }
This will be projected in the componet
It is very simple, the ng-content component tag is inside the parent component and replace with the ng-content tag. The issue that comes with if you pass a component within the ng-content that sub-component(child-component) are in-built within the parent component. It’ll not be destroyed when a child component is destroyed.
See here we import component in another component,
Hey!
app-other-component is constructed not within the app-my-content but within the component is calling it.
So, content projection is good for simple HTML code, but that stops being true after you start injecting the component.
import { Input } from '@angular/core'; import { Component, TemplateRef } from '@angular/core'; @Component({ selector: 'app-page-list', templateUrl: '', }) class PageList{ @Input() temRef:TemplateRef ; }
Parent component
hey!
In the above example, we created a template using ng-template and injected it as a parameter within the child component.
And next is that the child component is using it in a container, with the help of the ngTemplateOutlet directive.
Let’s understand the concept of ViewChild VS ContentChildimport { ContentChild, Input } from '@angular/core'; import { Component, TemplateRef } from '@angular/core'; @Component({ selector: 'app-page-list', templateUrl: '', }) class PageList{ @ContentChild('pageList',{static:true}) temRef:TemplateRef ; }
hey!
Here, we define the ContentChild decorator. The ViewChild decorator will find a child within the component. And that defined by its template while ContentChild finds a child in the content defined by the component.
Now we will see the whole example of the Angular reusable components.This example contains the following:
ng-template defines that you simply can render the content manually for full control over how the control displays.
mat-paginator is for navigating the paged information. And for that, we install the material in our angular project.
onEvent is that the event for paginating the list on the table.
The Button is for the add new employee with a material icon.
Now, this is the employepage.ts file.
import { Component, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { emp } from "../emp"; @Component({ selector: 'app-employepage', templateUrl: './employepage.component.html', styleUrls: ['./employepage.component.css'] }) export class EmployepageComponent implements OnInit { dataSource:emp[]; protected list:FormGroup; constructor() { } ngOnInit(): void { } }
Datasource adds the data of employees.
And within the list, we will access the data in the formgroup.
Formgroup is that the module of the angular/forms.
Emp is a class that name as emp.ts. Here it is:
export class emp{ title:string; search:string; actions:string; content:string; }
Now, the child component name as an employepage component of a parent component.
Ng-container defines the section of a page, without having created an additional element just for that.
ngTemplateOutlet defines the reference of the template and context object of the template.
Here is that the employe.component.ts file.
import { Component, ContentChild, OnInit, TemplateRef } from '@angular/core'; @Component({ selector: 'app-employe', templateUrl: './employe.component.html', styleUrls: ['./employe.component.css'], }) export class EmployeComponent implements OnInit { @ContentChild('title',{static:true}) titTemplate:TemplateRef; @ContentChild('actions',{static:true}) actTemplate:TemplateRef; @ContentChild('search',{static:true}) serTemplate:TemplateRef; @ContentChild('content',{static:true}) conTemplate:TemplateRef; constructor() { } ngOnInit(): void { } }
In this way, we created the angular components with the use of child and parent components.
Simple components are become harder to use and maintain if the complexity grows. That’s why produce the angular reusable components. By creating the angular reusable components, we are able to pass the important data in another component. And also accessing that data within the component. Reusable components in Angular are easy to use and maintain.
Build Your Agile Team
Let's rewind to the 1990s. Data used to be stored on servers and CEOs relied on basic tools to make optimal decisions. No dashboards, nothing. When you use Power BI with a solid...
Imagine walking into a meeting where critical decisions need to be made—fast. You need clear, flexible data that you can analyze on the spot. But what if your insights are locked inside...
Clear insights mean smarter decisions, and this is what data storytelling does. It helps you speak a language that you quickly understand. Like for example, you are a CTO dealing with...