JAVASCRIPT:
.directive('search', [function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
attrs.$set('value', 'Word...');
console.log(attrs);
}
};
}]);
And the value attribute is added, but not displayed. I think it has something to do with ngModel attribute not allowing to change value, but I've seen somewhere in AngularJS docs, that setting value programmatically is possible, so can someone please show me the way how?
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: In the end, I want to get it doing something as simple as displaying something like 'Search items...' before it's focused, when focused, set it to '', and when blured, check if value is '' and set it back to 'Search items...'.
I know it's pretty simple, and I already got this working once with outside JS function, but I feel like it's not the best solution to involve something like "getElementById", I think it must be possible with AngularJS from link function, it's just that I don't know how...
Edit 2: Different from placeholder. Is there a way to solve this? Say, if I needed to achieve something different from what I described in the first edit?