Add plugin for AngularJS
Create a card form in AngularJs =D
I did mine like this:
angular.module('app.Components.CreditCard', [])
.directive('creditCardForm', creditCardFormDirective)
.directive('creditCardContainer', creditCardContainerDirective);
function creditCardFormDirective () {
return {
restrict: 'A',
scope: true,
controller: function () {
var ctrl = this;
ctrl.fields = {};
ctrl.setField = function (name, element) {
ctrl.fields[name] = element;
}
},
link: function (scope, element, attrs, ctrl) {
// TODO check for ctrl.fields presence
var card = new Card({
form: element[0],
container: ctrl.fields.container[0],
formSelectors: {
numberInput: '[credit-card-number]',
expiryInput: '[credit-card-expiry]',
cvcInput: '[credit-card-cvc]',
nameInput: '[credit-card-name]',
},
debug: true
});
}
};
}
function creditCardContainerDirective () {
return {
restrict: 'EA',
require: '^creditCardForm',
link: function (scope, element, attrs, ccForm) {
ccForm.setField('container', element);
}
}
}
How would you use this directive?
If one of y'all wants to turn this into a plugin or a wiki document, I'd be much obliged :)
I use it (something) like this:
<div credit-card-form>
<input type="text" credit-card-number>
<input type="text" credit-card-name>
<input type="text" credit-card-expiry>
<input type="text" credit-card-cvc>
<div credit-card-container></div>
</div>
Thanks @thenikso, is working like a charm!
I'm closing this for now. If someone wants to contribute an Angular plugin, I would love to accept a PR. Thanks for all your time and thought.
Thanks @thenikso that worked like a charm. I tried the plugin recommended in the readme, but it was very buggy. Your method was very straight forward and I have no issues with it.