Angular Add & Get Custom Attribute Value

Today, We want to share with you Angular Add & Get Custom Attribute Value.In this post we will show you angular add attributes to element, hear for how to get data by id in angular 7 we will give you demo and example for implement.In this post, we will learn about Get Custom Attributes Value in Angular? with an example.

Angular Add & Get Custom Attribute Value

There are the Following The simple About angular 6 get element by id Full Information With Example and source code.

Read Also:  how to calculate percentage discount using calculator?

As I will cover this Post with live Working example to develop attributes binding in angular 7, so the how to get data by id in angular 4 is used for this example is following below.

How to Add & Get Custom Attribute Value in Angular?

src/app/app.component.ts

import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
    
  websites = [
    {id:1, name:"pakainfo"},
    {id:2, name:"ministackoverflow"},
    {id:3, name:"infinityknow"},
  ]
  
  clickEvent(e){
    var id = e.getAttribute('data-id');
    console.log(id);
  }
}

src/app/app.component.html

<h1>angular add and get custom attribute to element - Pakainfo.com</h1>
   
<ul>
  <li #websiteID *ngFor="let website of websites" [attr.data-id]="website.id">
    <button (click)="clickEvent(websiteID)">{{ website.name }}</button>
  </li>
</ul>

Web Programming Tutorials Example with Demo

Read :

Read Also:  what are the main components of a database system?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about how to get data by id in angular 4.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Simple Laravel CRUD Validation Tutorial
  2. Read Also:  Sudo Unable To Resolve Host Error in Linux - Fix sudo
  3. Read Also:  PHP Crop Resize Image while Uploading using jquery plugin
  4. Read Also:  Laravel 7 jQuery Ajax Request Tutorial
  5. Read Also:  SQL Remove Numeric Characters in String
  6. Read Also:  How to get last record from table using PHP Laravel
  7. Read Also:  PHP Sorting Multidimensional Array By Key
  8. Read Also:  Laravel 6 insert query Example
  9. Read Also:  Laravel 7 jQuery Ajax Request Tutorial
  10. Read Also:  How to get last record from table using PHP Laravel
CLOSEX