2014-05-19 37 views
0

我正嘗試在我寫的簡單窗體上使用AngularJS。 採用NG-選擇我,但是當表單驗證,我從選擇獲得的價值是我的首選陣列中的範圍,而不是實際的字符串我在形式發送數組值的角度ng選項

<section id="signin" ng-controller="Sign_in"> 
    <form method="post" action="xxxx.php"> 
     <div id="contact"> 
    <div class="input_label user"> 
     <label for="country">Pays</label> 
    </div> 
    <select ng-options="country for country in countries" name="country" ng-model="Country"></select> 
     </div> 
     <br> 
     <input type="submit"> 
    </form> 
</section> 

這裏是選擇角碼

angular.module('commande',[]).controller('Sign_in',function Sign_in($scope, $element) { 

$scope.countries = [ 
    "Afghanistan","Afrique du Sud","Albanie","Algérie","Allemagne","Andorre","Angola","Antigua et Barbuda","Arabie saoudite","Argentine","Arménie", 
    "Australie","Autriche","Azerbaïdjan","Bahamas","Bahrein","Bangladesh","Barbade","Belgique","Bélize","Benin","Bhoutan","Biélorussie","Bolivie", 
    "Bosnie-Herzégovine","Botswana","Brésil","Brunei","Bulgarie","Burkina Faso","Burundi","Cambodge","Cameroun","Canada","Cap Vert","Centrafrique", 
    "Chili","Chine","Chypre","Colombie","Comores","Congo démocratique","Congo","Corée du Nord","Corée du Sud","Costa Rica","Côte d'Ivoire","Croatie", 
    "Cuba","Danemark","Djibouti","Dominique","RépubliqueDominicaine","Egypte","Emirats Arabes Unis","Equateur","Erythrée","Espagne","Estonie","Etats-Unis", 
    "Ethiopie","Fidji","Finlande","France","Gabon","Gambie","Géorgie","Ghana","Grèce","Grenade","Groenland","Guatémala","Guinée","Guinée Bissau", 
    "Guinée équatoriale","Guyana","Haïti","Honduras","Hong Kong","Hongrie","Inde","Indonésie","Irak","Iran","Irlande","Islande","Israël","Italie", 
    "Jamaïque","Japon","Jordanie","Kazakhstan","Kenya","Kirghizstan","Kiribati","Koweït","Laos","Lesotho","Lettonie","Liban","Liberia","Libye", 
    "Liechtenstein","Lituanie","Luxembourg","Macédoine","Madagascar","Malaisie","Malawi","Maldives","Mali","Malte","Maroc","Marshall","Maurice", 
    "Mauritanie","Mexique","Micronésie","Moldavie","Monaco","Mongolie","Mozambique","Myanmar","Namibie","Népal","Nicaragua","Niger","Nigeria", 
    "Norvège","Nouvelle Zélande","Oman","Ouganda","Ouzbekistan","Pakistan","Palau","Palestine","Panama","Papouasie - Nouvelle Guinée","Paraguay", 
    "Pays-Bas","Pérou","Philippines","Pologne","Porto Rico","Portugal","Qatar","Roumanie","Royaume-Uni","Russie","Rwanda","Saint Christophe et Nevis", 
    "Saint Vincent et les Grenadines","Sainte Lucie","Salomon","Salvador","Samoa","São Tomé et Príncipe","Sénégal","Seychelles","Sierra Leone","Singapour", 
    "Slovaquie","Slovénie","Somalie","Somaliland","Soudan","Sri Lanka","Suède","Suisse","Surinam","Syrie","Swaziland","Tadjikistan","Taïwan","Tanzanie", 
    "Tchad","Tchéquie","Thaïlande","Tibet","Timor Oriental","Togo","Tonga","Trinité et Tobago","Tunisie","Turkmenistan","Turquie","Tuvalu","Ukraine", 
    "Uruguay","Vanuatu","Vatican","Vénézuéla","Vietnam","Yémen","Yougoslavie","Zambie","Zimbabwe" 
]; 
+0

您如何驗證表單? – Grundy

+0

我很確定錯誤不是來自表單驗證,無論如何我使用PDO '$ req = $ bdd-> prepare('INSERT INTO client_id(email,civilite,nom,prenom,date_naissance,adressse, code_postal,ville,pays) VALUES(?,?,?,?,?,?,?,?,?)' 或exit(print_r($ bdd-> errorInfo())); $ req->執行(陣列( '電子郵件'=> $電子郵件, 'civilite'=> $性別, 'NOM'=> $名, 'prenom'=> $姓名, 'date_naissance' => $生日, 'adressse'=> $地址, 'code_postal'=> $郵政編碼, '威樂'=> $城市, '支付'=> $國家 ));' –

回答

1

出於某種原因,你不能使用數組的值作爲價值選擇使用ngOptions。你將不得不這樣做:

<select name="country" ng-model="Country" > 
    <option ng-repeat="country in countries" value="{{country}}"> 
     {{country}} 
    </option> 
</select> 

如果你想也設置從Country值增加ng-selected到選項標籤,例如

<option ng-repeat="country in countries" value="{{country}}" ng-selected="country == Country"> 
    {{country}} 
</option> 
+0

這正是我所期待的,非常感謝! –

0

我認爲你需要應用一個過濾器來獲取值。

如果我是你,我會用出色的angular-ui typeahead directive與自舉3.工作中的代碼,然後將:

<input type="text" ng-model="selected" typeahead="country for country in countries | filter:$viewValue | limitTo:8" class="form-control"> 
+0

謝謝,我」我會立即嘗試 –