0

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.

Code:

<!doctype html>
<html lang="en">
<head>
  <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 + '" />'));
  </script>
</head>
<body ng-app="formExample">
  <script>
  angular.module('formExample', [])
    .controller('FormController', ['$scope', function($scope) {
      $scope.userType = '';
    }]);
</script>
<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>
 </form>
</body>
</html>

Here is the demo Link:

Demo Plunker

2 Answers 2

2

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

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

DEMO APP

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @Sajeetharan
@M-S Mark as answer if it has helped you
Definitely, Just waiting for the mark option to be enabled
How do I append class dynamically to the another span if the userType.length>0 plnkr.co/edit/vPuUWsFBtYKdxTKvXQSe?p=preview
you can use a function to apply stackoverflow.com/questions/14643836/…
0

Just check the input modal value as below,

<!doctype html>
<html lang="en">
<head>
  <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>
    angular.element(document.getElementsByTagName('head')).append(angular.element('<base href="' + window.location.pathname + '" />'));
    </script>
</head>
<body ng-app="formExample">
  <script>
  angular.module('formExample', [])
.controller('FormController', ['$scope', function($scope) {
  $scope.userType = '';
}]);
</script>
<form name="myForm" ng-controller="FormController" class="my-form">
  userType: <input name="input" ng-model="userType">
  <span ng-show="userType">show me!</span><br>
 </form>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.