Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally assign attribute value in angular 2?

I'm trying to learn the Angular 2. I have a simple material input tag and I wish to set it's value on a conditon.

<md-input value="dataSelected ? {{selectedDataName}} : ''"></md-input>

I tried to set [value] or dataSelected as {{dataSelected}} or (dataSelected) but it doesn't do the trick. Can someone lead me into right direction?

like image 381
Morgoth Avatar asked Dec 16 '16 08:12

Morgoth


1 Answers

Instead of value="dataSelected ? {{selectedDataName}} : ''" you can set it value with below possibile ways :

<md-input [attr.value]="dataSelected ? selectedDataName : ''"></md-input>

or

<md-input [value]="dataSelected ? selectedDataName : ''"></md-input>

or

<md-input value="{{dataSelected ? selectedDataName : ''}}"></md-input>
like image 156
ranakrunal9 Avatar answered Sep 25 '22 20:09

ranakrunal9