Reputation:
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:
Upvotes: 0
Views: 1168
Reputation: 1
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>
Upvotes: 0
Reputation: 222582
You need to check the scope variable userType's
length, It should be,
<span ng-show="userType.length>0">show me!</span><br>
Upvotes: 2