In an effort to create a dynamic form with different "widgets" based on field types and parameters stored in a database, I have been exploring directives for handling layout changes in response to various scenarios.
After experimenting with some examples, I've managed to come up with code that is somewhat functional:
HTML
<input type="text" ng-model="myModel" style="width: 90%"/>
<div class="zippy" zippy-title="myModel"></div>
Directive
myApp.directive('zippy', function(){
return {
restrict: 'C',
transclude: true,
scope: { title:'=zippyTitle' },
template: '<input type="text" value="{{title}}"style="width: 90%"/>',
link: function(scope, element, attrs) {
element.bind('blur keyup change', function() {
scope.$apply(read);
});
var input = element.children();
function read() {
scope.title = input.val();
}
}
}
});
While this solution seems to be functioning, albeit with some performance issues compared to standard AngularJS variable binding. I believe there is room for improvement. Can anyone provide insights on how to enhance this approach?