2014-10-27 77 views
0
<form name="companyProfileForm" autocomplete="false" novalidate ng-submit="OnSaveCompanyProfile(companyProfileForm.$valid)" ng-controller="companyProfileDataEntryController"> 
    <section ng-hide="!IsCompanyKnown();" class="row"> 
     <div class="small-12 medium-6 large-6 columns"> 
      <!--Industry--> 
      <section class="row"> 
       <div class="small-12 medium-12 large-12 columns" ng-class="{ 'has-error' : (companyProfileForm.Industry.$invalid && submitted) }"> 
        <div class="form-group"> 
         <label for="Industry">*Industry</label> 

         <select name="Industry" 
           ng-model="CompanyProfileModel.IndustryId" 
           ng-options="item.Id as item.Description for item in IndustryList" 
           required> 
          <option value=null>-- select an industry --</option> 
         </select> 

         <span class="help-block" ng-show="companyProfileForm.Industry.$invalid && submitted">Please select a value.</span> 
        </div> 
       </div> 
      </section> 
     </div> 
    </section> 
    <button></button> 
</form> 

不管我做什么,这个表格都会评估为真。我希望它抛出一个错误,即行业是必需的。提交后,它将转到一个可以在控制台上输出参数的功能。它每次都打印真实。为什么这种形式评估为真?

回答

0

您需要使用AngularJS ng-required指令,不需要。切换到所需的选择元素NG-所需=“真”:

<select name="Industry" ng-model="CompanyProfileModel.IndustryId" ng-options="item.Id as item.Description for item in IndustryList" ng-required="true"> 
    <option value=null>-- select an industry --</option> 
</select> 
0

一个表单元素上使用“必要” 将在角工作,只要你形式元素有一个NG提交=”动作()“和一个按钮,内容如下:

<button type='submit' ng-click='submit()'>SomeText</button> 
相关问题