M-S M-S - 1 month ago 4x
Javascript Question

How to display the span once the value is entered in input field? Angular JS

I have a scope variable defined in my controller, initially the value of my scope variable is empty.

I binded the ng-model to the input field and added ng-show to the span which needs to be display, once the value is entered in the input field.

When I entered a value in the input field, the span is not getting displayed.


<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<title>Example - example-ng-form-production</title>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>

<script type="text/javascript">
angular.element(document.getElementsByTagName('head')).append(angular.element('<base href="' + window.location.pathname + '" />'));
<body ng-app="formExample">
angular.module('formExample', [])
.controller('FormController', ['$scope', function($scope) {
$scope.userType = '';
<form name="myForm" ng-controller="FormController" class="my-form">
userType: <input name="input" ng-model="userType">
<span ng-show="myForm.input.length>0">show me!</span><br>

Here is the demo Link:

Demo Plunker


You need to check the scope variable userType's length, It should be,

<span ng-show="userType.length>0">show me!</span><br>