AngularJS Directive input binding
http://stackoverflow.com/questions/28844309/angularjs-directive-binding-input
by adamk33n3r
HTML
<div ng-app="testApp">
<div class="col-md-12" ng-controller="TestrouteCtrl as tr">
<input type="checkbox" ng-model="tr.user.admin" />
<form-input model="tr.user.admin"></form-input>
<form-input2 model="tr.user.admin" type="checkbox"></form-input2>
</div>
</div>
JavaScript
var app = angular.module('testApp', []);
app.controller('TestrouteCtrl', function($scope) {
this.user = {
admin: true
}
});
app.directive('formInput', function() {
return {
restrict: 'EA',
scope: {
model: '='
},
template: '<input ng-model="model" type="{{ type }}"/>',
link: function(scope, element, attrs) {
scope.type = "checkbox";
}
}
});
app.directive('formInput2', function() {
return {
restrict: 'EA',
scope: {
model: '=',
type: '@'
},
template: '<input ng-model="model" type="{{ type }}"/>',
link: function(scope, element, attrs) {
}
}
});