0

I have an input box using ng Ant design now am using the readonly attribute for the input field. once the user click on edit the readonly has to become the editable field. how to achieve this.

Code:

<i nz-icon type="edit" class="toolbar-icon" (click)="edit()"></i>
<input type="text" nz-input [ngModel]="'French'" [readonly]="true">

ts file:

edit() {
   console.log("function called");
}
0

2 Answers 2

1

You can use <input [readonly]="{{ variable }}>".

In your *.component.ts, initialize the variable:

private variable: boolean = true;

Edit 1

So this up is not working you need to

In your *.component.ts, initialize the variable:

  @Input() editable: boolean = false;
    edit() {
     console.log("function called");
     this.editable = true;
    }

And then you can use for example

<button (click)="edit()">Click me!</button>
<input type="text" [readonly]="!editable">

Sorry for first bad answer. Live demo here https://stackblitz.com/edit/angular-bei96r

Sign up to request clarification or add additional context in comments.

7 Comments

Did you put in edit function => this.variable = true ?
core.js:14597 ERROR Error: Uncaught (in promise): Error: Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected at column 0 in [{{ variable }}] in . <input [ERROR ->][readonly]="{{ variable }}">
@lakshmipriya i update answer, sorry for didn't try before i say answer, i forgot that's this first answer don't do job :)
thank you but its throwing this error. Cannot find name 'Input'.
import { Component, Input } from '@angular/core'; :)
|
0

The square are used to bind to a variable. And I don't think true is a variable in your ts file.

You can however pass true as a string.

<input type="text" nz-input [ngModel]="'French'" [readonly]="'true'">

Or remove the square brackets totally

<input type="text" nz-input [ngModel]="'French'" readonly="true">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.