Back to Browse

Conditional Directive in Angular | Directives | Angular 12+

17.1K views
Feb 13, 2022
13:21

In this lecture, let's learn how to add a directive to a component or an HTML element based on a given condition. If the condition assigned to directive returns true then apply that directive on that HTML element. But if it returns false, then do not apply that directive to the HTML element or component on which it is used. To learn how to implement this kind of logic, let's say we have a list of cards in the webpage. Now, we have a highlight directive which we want to apply only to that card which has the highest number of likes. This directive should not be applied on any other cards. Let's se how to achieve this. Learn about spread operator: https://youtu.be/nrw5Xo3VbJE Learn about Sorting an array: https://youtu.be/TaBSdB_Btx0 Project Code: https://drive.google.com/file/d/16SYON13Ld1xWVjGlMNXplSYT110qE868/view?usp=sharing

Download

1 formats

Video Formats

360pmp417.8 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Conditional Directive in Angular | Directives | Angular 12+ | NatokHD