How to restricts space in angular js

app.directive(‘disallowSpaces’, function() {
return {
restrict: ‘A’,

link: function($scope, $element) {
$element.bind(‘input’, function() {
$(this).val($(this).val().replace(/ /g, ”));
});
}
};
});
This directive can be invoked like this:

<input type=”text” disallow-spaces>