JAVASCRIPT:
.directive('search', [function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
attrs.$set('placeholder', 'Word...');
console.log(attrs);
}
};
}]);
Although the value attribute is being added, it isn't displayed. This issue may be related to the ngModel attribute not allowing changes to the value. However, based on what I've seen in the AngularJS documentation, it is possible to set the value programmatically. Could someone guide me on how to do this?
HTML:
<input type="text"
ng-model="query"
ng-init="inputClass='input-inactive'"
ng-class="inputClass"
ng-focus="inputClass='input-active'"
ng-blur="inputClass='input-inactive'"
ng-change="searchModelChange()"
search />
Edit: Ultimately, I want to have the input display 'Search items...' when idle, clear when focused, and revert back to 'Search items...' if empty when blurred.
I understand that achieving this functionality with an external JS function using "getElementById" may not be optimal. I believe there should be a way to accomplish this within AngularJS from the link function, but I'm unsure of how...
Edit 2: Is there a solution different from using placeholder? If I had a requirement beyond the scenario described in the first edit, how could I address it?