I'm currently using Angular 1.5
library and wants to create a component for simple Text Box like below.
Component JS
'use strict';
angular
.module('components')
.component('inputBox', {
bindings: {
label: '@',
name: '@',
type: '@',
classes: '@',
placeholder: '@',
maxlength: '@'
},
controllerAs: 'field',
templateUrl: 'app/components/inputBox.html'
});
Component Template
<input type="{{field.type || 'text'}}"
class="form-control {{field.classes}}"
id="{{field.name}}"
name="{{field.name || 'unnamed'}}"
maxlength="{{field.maxlength}}"
placeholder="{{field.placeholder}}" />
Usage in all Templates.
<input-box
label="Enter an account"
name="accountNumber"
type="number"
classes="form-control"
placeholder="Account Number"
maxlength="20"
// directives
ng-model="accountNumber"
ng-custom1="value1"
ng-custom2="value2"
ng-custom-validator="value4" />
I have two issues which is below where i need the best practices.
- I want to keep all directives extended in the usage template not part of component.
Which is best practice
@
or=
but i good understanding about this options.a. "@" ( Text binding / one-way binding )
b. "=" ( Direct model binding / two-way binding )
c. "&" ( Behaviour binding / Method binding )
Why this approach?
I have around 27 forms with many input types. I want to create the single component that will have all field label, input and error container.