In my AngularJS application, I have different complex inputs everywhere. For example, some inputs have a directive to use autocompletion with Google Places or with autocompletion from Twitter Bootstrap.
I'm searching for a way to make a directive which displays an erase button when we add some text like iOS feature.
I made this one, but the scope.erase
doesn't start, nor does the ng-show
.
Is it possible to add HTML after the text input and "play" with them inside the controller?
My test:
app.directive('eraseBtn', function($parse, $compile){
return {
require: 'ngModel',
restrict: "A",
transclude: true,
link : function(scope, element, attrs, model){
element.parent().append('<button ng-click="erase()" ng-show="model.length > 0" class="erase-btn">x</button>');
scope.erase = function(){
console.log('Erase test');
}
}
}
});
I don't want to use a template because all of my inputs' HTML are really different.