question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bind Value - How to use?

See original GitHub issue

This is probably working as intended but I figured I would ask.

I am using a reactive form, my control value is an array of objects. When I use bingLabel, everything is fine. When I bindValue to a property within the objects, it throws an error.

ERROR Error: Binding object with bindValue is not allowed.

cities: = [
      {id: '1', name: 'Vilnius'},
      {id: '2', name: 'Kaunas'},
      {id: '3', name: 'Pavilnys'} 
  ];
     
  ngOnInit(){
      this.heroForm = this.fb.group({
          city: [this.cities]
      });
  }

<ng-select 
   [items]="cities"
   placeholder="Select city"
   bindValue="id"
   bindLabel="name"
   formControlName="city">
</ng-select>

Should I be able to bind to the property of an object such as bindValue="cities.id" or bindValue="city.id"?

I may be over thinking this, seems to work without the bindValue there at all but was curious why I was getting the error.

https://plnkr.co/edit/eRnhdJBeIQhTTcmmK4Zv?p=preview

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
burakkiliccommented, Oct 31, 2017

How can we preselect multiple objects?

2reactions
ronbnsimcommented, Jun 4, 2018

I dont understand why they do this limitation??? if you remove the “warning” in the code in NgSelectComponent.prototype._isValidWriteValue to return true it works with objects just fine.

when this should be fixed alot of people here need to select objects…atleast let us work with the “compareWith” to recognize the object our self.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Difference between @bind and @bind-value - Stack Overflow
Short Version. @bind is an override of @bind-value with the event set to "onchange". These two commands are equivalent:
Read more >
How do you use bind-value and bind-value:event on a custom ...
This FAQ explains the topic " How do you use bind-value and bind-value:event on a custom component? ". You can submit your questions...
Read more >
ASP.NET Core Blazor data binding - Microsoft Learn
Razor components provide data binding features with the @bind Razor directive attribute with a field, property, or Razor expression value.
Read more >
PDOStatement::bindValue - Manual - PHP
Binds a value to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement. Parameters...
Read more >
Value Binding vs Data Binding - Telerik UI for Blazor
In this documentation, we will refer to Value Binding as the process of passing values between a component and its parent. Value binding...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found