0

I am working on color picker where i need to select 10 colors , I need to display the value as soon as the color picker select. It is updating the value when we are selecting with for loop but it is not updating the value when we directly print value. Please check below link - https://stackblitz.com/edit/github-puzsp8-kxtfe1?file=src/app/app.component.html

I might have missed something. But not able to get. Lets assume colors is Array object and <span>{{colors}}</span> this will not change value <span *ngFor="let c of colors">{{c}}</span> this one is updating correctly .

Why it is not updating if I print only colors . Thanks

3
  • Could you please describe a little bit more what you need exactly ? Commented Aug 28, 2018 at 9:57
  • 1
    <span>{{colors | json}}</span> seems to be working. Looks like angular issue> Actually in earlier version if you binded an object, it would simply showup as [object Object]. recently they had added this feature where they pretty print the object. You should never need to bind an object like how you are doing Commented Aug 28, 2018 at 9:58
  • @GauravMukherjee , Thanks a lot . It is working with <span>{{colors | json}}</span> .. I got confused because it was showing string but not updating. Thanks Again Commented Aug 28, 2018 at 11:27

3 Answers 3

1

Use json pipe for this.

<span>{{colors | json}}</span>
Sign up to request clarification or add additional context in comments.

Comments

1

i get the same as

<span *ngFor="let c of colors">{{c}}</span>

using

<span>{{colors.toString()}}</span>

1 Comment

Thanks . I checked , it was working with colors.toString() .
1

In earlier version of angular if you binded an object, it would simply show up as [object Object]. Recently they had added this feature where they pretty print the object. You should never need to bind an object like how you are doing anyways. Or if you need to, you should convert it to string first

1 Comment

Thanks for the explanation. Yes Earlier I have seen it will display - [object Object]. As per suggestion need to use either pipe or toString() . Thanks

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.