Giter VIP home page Giter VIP logo

angulardirectives_sample1-builtindirectives's Introduction

Built-in Directives

https://angular.io/guide/built-in-directives

https://stackblitz.com/~/github.com/luiscoco/AngularDirectives_Sample1-BuiltInDirectives

In Angular, built-in directives are pre-defined instructions that can be applied to HTML elements to manipulate their behavior or appearance. These directives are provided by Angular itself and are available for use without requiring any additional configuration or imports.

Here are some commonly used built-in directives in Angular:

*ngIf

This directive is used to conditionally render elements in the DOM based on a given expression. It adds or removes the element from the DOM based on the truthiness of the expression.

<div *ngIf="isLoggedin">User is logged in</div>

In this example, the div element will only be displayed if the isLoggedin property evaluates to true.

*ngFor

This directive is used for iterating over a collection and rendering elements dynamically. It allows you to repeat a portion of HTML markup for each item in an array or an iterable object.

<ul>
  <li *ngFor="let item of items">{{ item }}</li>
</ul>

In this example, each item in the items array will be rendered as a list item (li).

*ngSwitch

This directive is used for conditionally displaying content based on multiple cases. It works similar to a switch-case statement.

<div [ngSwitch]="color">
  <div *ngSwitchCase="'red'">Red color selected</div>
  <div *ngSwitchCase="'blue'">Blue color selected</div>
  <div *ngSwitchCase="'green'">Green color selected</div>
  <div *ngSwitchDefault>Color not selected</div>
</div>

In this example, based on the value of the color variable, the corresponding div block will be displayed.

[ngClass]

This directive is used to dynamically apply CSS classes to an element based on a condition.

<div [ngClass]="{ 'active': isActive, 'disabled': isDisabled }">Some content</div>

In this example, the CSS class active will be applied if the isActive property is true, and the disabled class will be applied if the isDisabled property is true.

These are just a few examples of the built-in directives in Angular. There are several others available that provide various functionalities to make development easier and more efficient.

angulardirectives_sample1-builtindirectives's People

Contributors

luiscoco avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.