2016-03-28 62 views
0

我想填充下拉列表,但我無法獲得要顯示的選項,我找不出原因。我填充在我的控制器的選項與此:不會顯示在下拉列表中的角度選項

var qOptions = []; 
if (value.vchChoice1 != '') { 
    qOptions.push(value.vchChoice1); 
    }; 
if (value.vchChoice2 != '') { 
    qOptions.push(value.vchChoice2); 
    }; 
if (value.vchChoice3 != '') { 
    qOptions.push(value.vchChoice3); 
}; 
if (value.vchChoice4 != '') { 
    qOptions.push(value.vchChoice4); 
    }; 
$scope.followingquestions[key].qOptions = qOptions; 
    qOptions = []; 

然後在我的HTML這樣的:

<select ng-model="f.vchShortAnswer"> 
    <option value="">--Please Select--</option> 
    <option ng-repeat="z in f.qOptions" value="{{z}}">{{z}}</option> 
</select> 

下面是完整的HTML代碼,以防萬一有那麼點意思,導致該選項出現然後消失:

  <div ng-repeat="f in followingquestions"> 
      <div ng-switch="f.ClusterTypeID"> 
       <div ng-switch-when="1048576"> 
        <div class="row row-relative"> 
         <div class="col-md-12"> 
          <div ng-bind-html="f.vchQuestionText | trustedhtml"></div><br /> 
          <div> 
           <table> 
            <thead style="background-color:#b1d6f1"> 
             <tr> 
              <th>{{headers.vchTextElementOneHeader}}</th> 
              <th>{{headers.vchTextElementTwoHeader}}</th> 
             </tr> 
            </thead> 
            <tbody> 
             <tr ng-repeat="answ in headers.Answers"> 
              <td>{{answ.vchTextElementOne}}</td> 
              <td>{{answ.vchTextElementTwo}}</td> 
             </tr> 
            </tbody> 
           </table> 
          </div> 
         </div> 
        </div><br /> 
       </div> 
       <div ng-switch-when="1"> 

        <div class="row row-relative"> 
         <div class="col-md-9"> 
          <span ng-bind-html="f.vchQuestionText | trustedhtml"></span>&nbsp;<span ng-if="f.vchToolTip != null" style="cursor:pointer"><i class="glyphicon glyphicon-info-sign" tooltip="{{f.vchToolTip}}"></i></span> 
         </div> 
         <div class="col-md-3 col-border" ng-switch="f.vchAnswerTableName"> 
          <div class="col-border-padding"> 
           <div ng-switch="f.AnswerTypeID"> 
            <div ng-switch-when="1"> 
             <input type="radio" ng-model="f.vchShortAnswer" value="Yes" style="width:20px" />&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" data-ng-model="f.vchShortAnswer" value="No" style="width:20px" />&nbsp;No 
            </div> 
            <div ng-switch-when="5"> 
             @*<select data-ng-model="f.vchShortAnswer" ng-options="qO as qO for qO in f.qOptions" class="form-control">*@ 
             <select ng-options="z as z for z in f.qOptions" ng-model="f.vchShortAnswer" class="form-control"> 
              <option value="">--Please Select--</option> 
             </select> 
            </div> 
            <div ng-switch-when="8"> 
             <textarea ng-model="f.vchLongAnswer" style="width:100%"></textarea> 
            </div> 
            <div ng-switch-when="10"> 
             <input type="text" ng-model="f.dteDateAnswer" /> 
            </div> 
            <div ng-switch-when="9"> 
             <input type="text" ng-model="f.decNumericAnswer" /> 
            </div> 
           </div> 
          </div> 


         </div> 
        </div> 
        <div ng-repeat="child in f.Dependents"> 
         <div class="row row-relative"> 
          <div class="col-md-9"> 
           <span ng-bind-html="child.vchQuestionText | trustedhtml"></span>&nbsp;<span ng-if="child.vchToolTip != null style=" cursor:pointer""><i class="glyphicon glyphicon-info-sign" tooltip="{{child.vchToolTip}}"></i></span> 
          </div> 
          <div class="col-md-3 col-border" ng-switch="child.vchAnswerTableName"> 
           <div class="col-border-padding"> 
            <div ng-switch="child.AnswerTypeID"> 
             <div ng-switch-when="8"> 
              <div ng-switch="child.bitDependentOnParent"> 
               <div ng-switch-when="true"> 
                <div ng-if="p.vchShortAnswer == child.vchParentAnswerMakesEnabled"> 
                 <textarea ng-model="child.vchLongAnswer" style="width:100%"></textarea> 
                </div> 
                <div ng-else> 
                 <textarea ng-model="child.vchLongAnswer" style="width:100%" disabled></textarea> 
                </div> 
               </div> 
               <div ng-switch-when="false"> 
                <textarea ng-model="child.vchLongAnswer" style="width:100%"></textarea> 
               </div> 
              </div> 
             </div> 
             <div ng-switch-when="1"> 
              <input type="radio" data-ng-model="form.child.vchShortAnswer" value="Yes" style="width:20px" />&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" data-ng-model="form.child.vchShortAnswer" value="No" style="width:20px" />&nbsp;No 
             </div> 

            </div> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 

我知道有在f.qOptions值,我可以使用僅僅用div標籤重複顯示它們,但我不能讓他們在下拉列表裏顯示ST。

我也試過以下,但他們仍然沒有顯示:

ng-options="z as z for z in f.qOptions" 

更爲蹊蹺......值顯示簡單,然後就消失了!

我覺得我缺少一些簡單的東西,因爲我在選擇選項列表中顯示其他列表的方式與我上面所做的幾乎相同。任何援助非常感謝!

+0

你認爲f是什麼? –

+0

f是followinquestions。如果我刷新瀏覽器,則會顯示某個值。 –

+0

你可以創建plunker或snippet嗎? –

回答

2
$scope.qOptions = []; 
if (value.vchChoice1 != '') { 
    $scope.qOptions.push(value.vchChoice1); 
}; 
if (value.vchChoice2 != '') { 
    $scope.qOptions.push(value.vchChoice2); 
}; 
if (value.vchChoice3 != '') { 
    $scope.qOptions.push(value.vchChoice3); 
}; 
if (value.vchChoice4 != '') { 
    $scope.qOptions.push(value.vchChoice4); 
}; 
$scope.followingquestions[key].qOptions = $scope.qOptions; 


<select ng-options="z as z for z in f.qOptions" ng-model="f.vchShortAnswer"> 
    <option value="">--Please Select--</option> 
</select> 
+0

謝謝,但我試過,仍然沒有。 –

+0

你沒有將你的數組添加到作用域中。使用$ scope.qOptions = []; – luk492

+0

謝謝!就是這樣! - 好吧,我認爲是這樣,但數值顯示然後又消失了! –

相關問題