Welcome to %s forums

<No. 1 Community for developers, by developers/>

Login Register

How to get an attribute value from custom tag in Angular?

Get support on Angular & Typescript related technology.
Post Reply
admin
Site Admin
Posts: 45

How to get an attribute value from custom tag in Angular?

Post by admin » Tue Aug 27, 2019 6:16 pm

app.component.html

Code: Select all

<password #passwordInput minlength="5" maxlength="11"> </password>


<button (click)="logValues()">Log Value</button>

{{ passwordInput.maxlength | json }} 

app.component.ts

Code: Select all

import { Component, ViewChild } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  @ViewChild('passwordInput', { static: false }) password;

  logValues() {
    console.log(this.password.maxlength);
  }
}
app.module.ts

Code: Select all

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';


@NgModule({
  imports:      [ BrowserModule, FormsModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }
Created a demo here https://stackblitz.com/edit/developersd ... om-element

Post Reply