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.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

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.

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 :

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.   Send Windows Push Notification Services using PHP
  2.   AngularJS Login Script using PHP MySQL
  3.   Simple AngularJS Shopping Cart Application
  4.   How to display pdf file in HTML - PDF Viewer HTML5 Example
  5.   How to Configure Virtual Host in XAMPP
  6.   Woocommerce Featured Image URL and Gallery images in Wordpress
  7.   Remove Duplicates value From Array in VueJS
  8.   PHP Creating Unique Title Slugs in Laravel
  9.   how to install PHP Accelerator in Xampp
  10.   Get custom product attributes in Woocommerce

Leave a Reply

Your email address will not be published. Required fields are marked *