To optimize performance, consider incorporating the ng-model
directly from the server side.
If implementing it on the client-side is necessary, you can create a personalized directive that automatically adds the ng-model
during compilation:
app.directive('myModel', function($compile) {
return {
restrict: 'A',
replace: false,
priority: 1000,
terminal: true,
link: function (scope, element, attrs) {
attrs.$set('ngModel', attrs.name);
attrs.$set('myModel', null);
$compile(element)(scope);
}
};
});
Usage example:
<input type="text" name="myinputname" my-model />
Upon compilation, it will transform into:
<input type="text" name="myinputname" ng-model="myinputname" />
Explore this concept further: http://plnkr.co/edit/hBQQMDTr6cYtHzFvoAaQ?p=preview