0

I think, everyone knows, how interpolation works, and we can easily interpolate single variable (may be this interpretation is not fully correct, but you will understand what I mean when will take a look at the code). But what if we want to switch between two different variables dynamically? For example, we have two class properties:

public first: string = '"first" variable activated';
public second: string = '"second" variable activated';

And have two radio buttons, bound to activeVariableName class property:

<input type="radio" value="first" [(ngModel)]="activeVariableName">
<input type="radio" value="second" [(ngModel)]="activeVariableName">

We can interpolate like this:

<h1>{{activeVariableName}}</h1>

But this way, we will see just first or second, which are class properties names.

So my question is: "How to display values of this properties, but not just names?"

Here is a STACKBLITZ

2
  • its a valid question in all honesty, its a simple mistake that quite a lot of people would make Commented May 14, 2018 at 11:19
  • If somebody think so and this question will help someone - not a problem, let's keep it open Commented May 14, 2018 at 11:21

1 Answer 1

4

You missed off the binding brackets [], so the values are first and second. try:

<input type="radio" [value]="first" [(ngModel)]="activeVariableName">
<input type="radio" [value]="second" [(ngModel)]="activeVariableName">
Sign up to request clarification or add additional context in comments.

1 Comment

Very simple and clear, thanks a lot! I'll accept your answer after timeout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.