I need to add class to input parent if input is not empty or focus because I want to change label position.
<div class="input-field">
<input type="email" name="email" ng-model="email" required />
<label for="email">Email</label>
</div>
I can do this:
<div class="input-field" ng-class="{ active: signIn.email.$viewValue.length > 0 || isFocus }">
<input type="email" name="email" ng-model="email" ng-focus="isFocus=true" ng-blur="isFocus=false" required />
<label for="email">Email</label>
</div>
But I have many inputs and my code will be very large and ugly.
How can I do it better?
Thank you.
Go with attribute directive where you can have logic which class you need to add to input-filed.
angular.directive('myClass', function() {
return {
restrict: 'A',
link: function (scope, element,attr) {
// your logic
}
};
or
$scope.myClass = "";
<div class="input-field" ng-class="myClass" />
angularjs : setting class attribute in a directive template
I am trying to change custom icon of video, when video is toggled(Play/Pause). ngAfterViewInit() { const vdoCont = document.querySelector('.video-player'); const vdo = vdoCont.querySelector('video')...
I am trying to change custom icon of video, when video is toggled(Play/Pause). ngAfterViewInit() { const vdoCont = document.querySelector('.video-player'); const vdo = vdoCont.querySelector('video')...
I'm trying to implement an image preview. It works fine until i came to a problem where i need to prevent the input file to not change. JSFIDDLE When trying to change to image its fine. After ...
I'm trying to implement an image preview. It works fine until i came to a problem where i need to prevent the input file to not change. JSFIDDLE When trying to change to image its fine. After ...
This is my data with 5 arrays. What I wish to achieve is to combine id and name and the new array should have 5 different playname values. It can be in either an array or new key like playername1. [ ...
This is my data with 5 arrays. What I wish to achieve is to combine id and name and the new array should have 5 different playname values. It can be in either an array or new key like playername1. [ ...
I have an fuctions in JS like below. manager.addDocument('en', 'bye bye take care', 'greetings.bye'); manager.addDocument('en', 'okay see you later', 'greetings.bye'); manager.addDocument('en', ...
I have an fuctions in JS like below. manager.addDocument('en', 'bye bye take care', 'greetings.bye'); manager.addDocument('en', 'okay see you later', 'greetings.bye'); manager.addDocument('en', ...