htmlangulartypescriptangular8

How can I set input placeholder text in component file in Angular


I'm new to Angular and Typescript. I have the input with a placeholder below, is there a way to change the placeholder text from my component file?

<input id="city" class="form-control" placeholder="City or Town">

Solution

  • You can just bind the placeholder attribute. Stackblitz

    <input id="city" class="form-control" [placeholder]="placeholder">
    
    import { Component } from '@angular/core';
    
    @Component({
      selector: 'my-app',
      templateUrl: './app.component.html',
      styleUrls: [ './app.component.css' ]
    })
    export class AppComponent  {
      placeholder = 'Angular';
    }