Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear x icon focus out issue using angularjs

Tags:

angularjs

I need x icon for removing input field values 1. When user type anything "x" icon will be displayed

  1. If no values available in input box x will be hide

  2. When values available in input box and focus out the input box we need to hide the x icon and focus in we need to show x icon again.

When we add ng-blur="count = !count" (Focus out i need to hide x if input has values) in input box my expectation will be failed.

CODE:

<span ng-show="name && count" ng-click="name=''" style="position: absolute;left: 203px;cursor;pointer;">X</span>
Name: <input ng-model="name" ng-focus="count = !count" ng-init="count=false" >
<p>{{count}}</p>

Any one please helps me how to fix this issue

like image 439
CodeMan Avatar asked Mar 08 '26 13:03

CodeMan


1 Answers

There's something wrong with jsfiddle. The snippet below (copy pasted from your question) works fine.

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.name="";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">

<span ng-show="name && count" ng-click="name=''" style="position: absolute;left: 203px;">X</span>

Name: <input ng-model="name" ng-focus="count = !count" ng-init="count=false" ng-blur="count = !count">

<p>{{count}}</p>
</div>
like image 131
gyc Avatar answered Mar 10 '26 14:03

gyc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!