获取所需的输入状态

时间:2016-03-25 18:31:14

标签: angularjs

JSBin中的此代码:

我想使用AngularJS模型

在需要输入电子邮件时隐藏或显示星号

已经检查了这些:

  • 电子邮件。$ validators.required
  • email.required
  • email.ngRequired
  • email.ngRequired()

HTML

<body ng-app="myApp">
    <form ng-controller="controllerUser">
        <div class="row">
            <div class="rt-grid-2 label-form">
                <span class="required">*</span>
                <span>User Type</span>
            </div>
            <div>
                <select id="userType" name="userType" ng-model="userType" ng-required="true">
                    <option value=''>select</option>
                    <option value='personal'>Personal</option>
                    <option value='company'>Company</option>
                </select>
                <div class="errorMessage"></div>
            </div>
        </div>
        <div class="row">
            <div class="rt-grid-2 label-form">
                <span class="required" ng-hide="email.required">*</span>
                <span>E-mail</span>
            </div>
            <div>
                <input type="email" id="email" name="email" ng-model="email" ng-maxlength="50" ng-required="isCompany()">
                <div class="errorMessage"></div>
            </div>
        </div>
        <input type="submit" value="Send">
    </form>
</body>

的Javascript

var myApp = angular.module('myApp', []);

myApp.controller('controllerUser', ['$scope', function ($scope) {
  $scope.isCompany = function () {
    return $scope.userType == 'company';
  };
}]);

我尝试了不同的形式但是没有工作。

0 个答案:

没有答案