Über eine einfache Directive kann man bei input-Elementen vom Typ „text“ das Binden der aktuellen Eingabe an das Model durchführen:
module.directive(‚UpdateOnEnter‘, function () {
return {
restrict: ‚A‘,
require: ’ngModel‘,
link: function (scope, element, attrs, ctrl) {
element.on(„keyup“, function (ev) {
if (ev.keyCode == 13) {
ctrl.$commitViewValue();
scope.$apply(ctrl.$setTouched);
}
});
}
}
});
Beispiel für ein input-Element:
<input type=“text“ class=“form-control input-xs text-right“ tabindex=“15″ ng-model=“palette.menge“ onfocus=“this.select()“ update-on-enter />