Teraz próbuję uzyskać wartość z rozwijanej listy select, ale ona zwraca wartość undefined. Rzecz jest w poziomie html To działa jak oczekujemy, Oto mój kod:Wybrana wartość Angularjs jest niezdefiniowana.
<div class='subcontent'>
<input id="me" type="radio" class='choosemethod' ng-model="paymentmethod" value="Y"><label for="me" class='choosemethod'>Me</label>
<input id="company" type="radio" ng-model="paymentmethod" value="N" class='choosemethod'><label for="company" class='choosemethod'>My Company</label><br/>
<span class='helptext'>Who makes payments to this account?</span><span class='help' style='margin-left:20px;width:20px;height:20px;'>help</span>
</div>
<div class='paymentmethods subcontent' ng-switch on="paymentmethod">
<select ng-model='selectedmethod' ng-init="selectedmethod=Memethods[0]" id='methods' ng-switch-when='Y'>
<option ng-repeat="method in Memethods" value="{{method}}">{{method}}</option>
</select>
<select ng-model='selectedmethod' ng-init="selectedmethod=companies[0]" ng-switch-when='N' style='float:left'>
<option ng-repeat='companyoption in companies' value="{{companyoption}}">{{companyoption}}</option>
</select>
<div class='clear'></div>
<label for ='methods'>Payment Method</label><span class='help' style='margin-left:20px;width:20px;height:20px;'>help</span>
</div>
w JS:
$scope.Memethods = ['Same as Card/Account Name','American Express','American Express Corp','Cash','Checking','MasterCard','My Visa','VISA'];
$scope.companies = ['Company Paid','MyAMEX'];
to widać dobrze w strony, ale gdy próbuję uzyskać wartość, to pokazuje niezdefiniowany. dowolny pomysł?
Czy zajmowałeś się konfiguracją wybranych opcji za pomocą dyrektywy ng-options? Wtedy nie musisz sam generować znaczników opcji i ma on również inne zalety. Stwierdziłem, że jest łatwiej, niż się spodziewałem, gdy tylko spróbowałem. Dokumenty mogą wyjaśnić to znacznie lepiej niż ja: https://docs.angularjs.org/api/ng/directive/ngOptions –