Giter Site home page Giter Site logo

Comments (13)

AlcheXie avatar AlcheXie commented on June 14, 2024 1

my way to solve ng-model binding:

add "searchStr: '=ngModel' in the directive's internal scope, like:

return {
restrict: 'EA',
require: '^?form',
scope: {
selectedObject: '=',
disableInput: '=',
......
inputName: '@',
searchStr: '=ngModel'
}
......
}

that can be use ng-Model as input element in form.

from angucomplete-alt.

ghiden avatar ghiden commented on June 14, 2024

What do you mean by predefining the selectedObject?

from angucomplete-alt.

jsonmurphy avatar jsonmurphy commented on June 14, 2024

For instance, when implementing CRUD functionality, updating a record in the form requires the model to be loaded and the fields populated with the current data. So essentially I have a field in my model that I've set to the selected-object but when its loaded the angucomplete field is blank.

// coming from sever
{ name: "Foo" }

// client side
....
selected-object="name"
....

I've already managed to find a workaround/alternative. I simply hide the field and show a label with the data if its defined then allow the user to click an "edit" link that will clear the data, hide the label and show the field.

from angucomplete-alt.

ghiden avatar ghiden commented on June 14, 2024

Would it be useful if we have direct two-way bind mode?
Currently there is an internal ng-model in the directive.
But if is just regular two-way bind model, this kind of behavior is easier.

from angucomplete-alt.

jsonmurphy avatar jsonmurphy commented on June 14, 2024

It might be useful. However, since it seems I'm the only one with this issue, I wonder if people are generally satisfied with the default behaviour. If it's not going to break the current API and it's easier to maintain then go for it! otherwise i'd wait for more people to request the feature/enhancement.

from angucomplete-alt.

cdorner avatar cdorner commented on June 14, 2024

+1

from angucomplete-alt.

ghiden avatar ghiden commented on June 14, 2024

Being able to set initial value for the internal model would help?
The usecase I'm thinking about is updating a model such as say user model that has

name: 'John'
age:     28
country: 'New Zealand'

With this user model, I might use angucomplete-alt for selecting country.
For creating, you can use the directive as it is.
But for updating, the form needs to start with initial value, 'New Zealand', then it should be able to update with new value.
So, I thought being able to set the initial value for internal model solve this usecase.
Please take a look at the latest commit in which I added initial-value feature. I also added one example for this. http://ghiden.github.io/angucomplete-alt/

from angucomplete-alt.

foozee avatar foozee commented on June 14, 2024

@ghiden yes your idea is exactly what's needed, but I have a little problem with it.... I'm loading the models from a backend, which is why it always results in a blank string at linking time, the initial-value seems like it doesn't work, however I've tested it with an explicitly set string and tada it worked like magic, but in most cases a user doesn't have the string ready while the directive is still at linking phase, I've created a PR #26.

Thanks for keeping this handy module maintained and updated :)

from angucomplete-alt.

jsonmurphy avatar jsonmurphy commented on June 14, 2024

Yes, this is exactly what I'm looking for and I especially like the fact that you've added input-changed as this was another thing i had to (trivially) workaround. I haven't tested it myself as yet but the demo seems to have the right behavior. Thanks for all your hard work.

from angucomplete-alt.

lowi avatar lowi commented on June 14, 2024

I have used ng-init to populate the data for the selected-object instead of initial-value (initial-value seems to only fill the value for the textbox).

from angucomplete-alt.

samirgit avatar samirgit commented on June 14, 2024

this solved ng-model binding for me :
first add to the scope inside the return :

  return {
    restrict: 'EA',
    require: '^?form',
    scope: {
      ngModel: '=',
}

second add to the link function :

      scope.$watch('ngModel', function(value, old){ 
          // console.log(value)
          scope.searchStr = scope.ngModel;
      });

i know it is bad messing with the core but it was necessary for my project.
Thanks for this good plugin

from angucomplete-alt.

DavidePastore avatar DavidePastore commented on June 14, 2024

👍

from angucomplete-alt.

ghiden avatar ghiden commented on June 14, 2024

Use initial-value with object.

from angucomplete-alt.

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.