Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular directive for 1.x #79

Closed
nosir opened this issue Aug 13, 2016 · 10 comments
Closed

Angular directive for 1.x #79

nosir opened this issue Aug 13, 2016 · 10 comments

Comments

@nosir
Copy link
Owner

nosir commented Aug 13, 2016

Coming soon... but for 1.x

@MattiSG
Copy link

MattiSG commented Aug 13, 2016

It was actually when implementing an Angular directive that did not discriminate on its element that I came to need #80. If that's of any use to you, here is a WIP on how I set up Cleave within a directive. That can maybe give an idea of a slightly complex use case.

@nosir
Copy link
Owner Author

nosir commented Aug 13, 2016

@MattiSG I'm on a cleave directive this weekend, which will only need you add it to the input field. Will let you know then to see if it can fit your need.

@OClement
Copy link

@nosir
I'm actually interested in a directive as well for an internal project at work
And was starting to play with this just now but then saw you stared working on one as well

I'm curious if you'd have some kind of ETA for this?
I was planning on seeing if I could build simple one that fits my needs in particular, but if you have something on the way and it's bound to be usable relatively soon I might focus on something else

Or if you think you have something that makes sense but don't intend on releasing it any time soon, maybe you could share what you have and I could use that as starting point?

Much appreciated

@nosir
Copy link
Owner Author

nosir commented Aug 14, 2016

@OClement It's almost there, will be like this: https://jsfiddle.net/nosir/1vbeLtp8/
Just published what I got to master, so you can refer to dist/cleave-angular.min.js.
Please be aware this is not completely done yet, still need to deal with the raw value, but other than that, I think that's it.

@ganySA
Copy link

ganySA commented Aug 15, 2016

angular2 component 👍

@trjiang trjiang changed the title Angular directive Angular directive for 1.x Aug 15, 2016
@nosir
Copy link
Owner Author

nosir commented Aug 15, 2016

Okay guys, Angular 1.x directive released.

Doc: https://github.com/nosir/cleave.js/blob/master/doc/angularjs-directive-usage.md
Fiddle: https://jsfiddle.net/nosir/q58sh22t/

As for Angular2 component, it's in the plan but won't be here soon.

@OClement
Copy link

@nosir
That was quick! Thanks, seems to be working great

I took a quick look and noticed you were using $watch to achieve the desired behaviour
Not to say that this is not a good approach, but since I started working on one too I thought I would share the code as well

It is using Formatters/Parsers on ngModelController instead of watchers
Different approach, same results (although technically one might say formatters/parsers would be a bit faster but that's probably a different discussion)

It still is a work in progress: http://plnkr.co/edit/PfRVzZqL5htotsPNq8xQ?p=preview

@nosir
Copy link
Owner Author

nosir commented Aug 16, 2016

@OClement cool, will have a look at night. Don't like watching either.

@MattiSG
Copy link

MattiSG commented Aug 16, 2016

From the link I sent above:

controller.$parsers.push(formatter.getRawValue.bind(formatter));

To use the $formatters, you'd need to make the formatter accessible without event binding ;) #80

@nosir
Copy link
Owner Author

nosir commented Aug 16, 2016

Okay, thanks @MattiSG @OClement , changes released:

  • use formatters/parsers
  • ng-model is binding to raw value

Doc: https://github.com/nosir/cleave.js/blob/master/doc/angularjs-directive-usage.md
Fiddle: https://jsfiddle.net/nosir/q58sh22t/

@nosir nosir closed this as completed Aug 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants