一旦在输入字段中输入值,如何显示跨度? Angular JS

时间:2016-09-08 02:09:10

标签: javascript jquery angularjs

我在我的控制器中定义了一个范围变量,最初我的范围变量的值是空的。

我将ng-model绑定到输入字段,并在输入字段中输入值后,将ng-show添加到需要显示的范围内。

当我在输入字段中输入值时,不会显示范围。

代码:

var playerStore = Ext.create('Ext.data.Store', {
    model: 'Player',
    proxy: {
        type: 'ajax',
        useDefaultXhrHeader: false,
        headers: {
            'Content-Type': 'application/json; charset=utf-8; Cache-Control: no-cache;',
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE',
            'Access-Control-Max-Age': '3600',
            'Access-Control-Allow-Headers': 'Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization'
        },
        noCache: false,
        reader: {
            type: 'json'
        }
    }
});

以下是演示链接:

Demo Plunker

2 个答案:

答案 0 :(得分:3)

你需要检查范围变量 userType's 长度,它应该是,

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

DEMO APP

答案 1 :(得分:0)

只需检查输入模态值,如下所示

<!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>