Git Product home page Git Product logo

Comments (9)

rubenv avatar rubenv commented on August 17, 2024

Should work, but an ng-model directly on the scope won't:

  $scope.foo = null;
  $scope.bar = null;

https://egghead.io/lessons/angularjs-the-dot

from angular-select2.

TheYves avatar TheYves commented on August 17, 2024

I'm sorry, I don't understand what you mean. In my plunker you can see that with regular selectboxes I can use objects where with select2 it doesn't work. Whatever I choose from the list, the model is always set to the last entry in the list.

from angular-select2.

rubenv avatar rubenv commented on August 17, 2024

I'm sorry, I don't understand what you mean.

Check the video I linked. Anyway, that's not an angular-select2 issue, but you will be in trouble if you don't learn it.

As for objects: values in the select2 widget are keyed by their toString value, so if your objects define unique toString values, it should work. If not, I suggest you don't use objects as values (it's ugly anyway), use an index key.

from angular-select2.

ramonwenger avatar ramonwenger commented on August 17, 2024

Hey rubenv

Thank you for that awesome select2-wrapper!

I am running into the same problem as TheYves though.

AngularJS can assign whole objects to a variable in a select (which you say is ugly, can you elaborate on that?), but the directive assigns the object's toString-method as array key, which leads to the last item in the array being selected, no matter which element was clicked on in the dropdown.

Might I suggest a solution where the directive checks wether or not the value is a String or an object, and if it's an object check for an id (or even better, look for the "track by"-attribute of the query string)?

If you are open to the suggestion I can even write the functionality and make a pull request.

Regards

from angular-select2.

rubenv avatar rubenv commented on August 17, 2024

Might I suggest a solution where the directive checks wether or not the value is a String or an object, and if it's an object check for an id (or even better, look for the "track by"-attribute of the query string)?

Sure, track by makes total sense!

from angular-select2.

TheYves avatar TheYves commented on August 17, 2024

@DonHaron have you already implemented your suggestion? I would be very interested. :)

from angular-select2.

ramonwenger avatar ramonwenger commented on August 17, 2024

@TheYves I started it and made it work, but it was rubbish and not in line with the ngSelect directive, and broke other parts of the select2-directive. So I will have to do a proper rewrite based on ngSelect. I didn't get to it yet though...

from angular-select2.

TheYves avatar TheYves commented on August 17, 2024

Okay, thanks for the reply.

from angular-select2.

buremba avatar buremba commented on August 17, 2024

Any update on this issue?

from angular-select2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.