Это мой выбор
<select ng-options="country.country for country in countries" formControlName="country"></select></label>
, а это машинопись:
import { Component } from '@angular/core';
import { AuthService } from '../../services/auth/auth.service'
import { Router, Params } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FirestoreService } from '../../services/firestore/firestore.service';
import { User } from '../../models/user/user.model';
import countriesJSON from '../../json/countries-and-states.json';
@Component({
selector: 'app-login-register',
templateUrl: './login-register.component.html',
styleUrls: ['./login-register.component.css']
})
export class LoginRegisterComponent {
registerForm: FormGroup;
errorMessage: string = '';
successMessage: string = '';
users: User[];
countries = countriesJSON.countries;
constructor(
public authService: AuthService,
private router: Router,
private fb: FormBuilder,
private fireservice: FirestoreService
) {
this.createForm();
}
createForm() {
this.registerForm = this.fb.group({
email: ['', Validators.required ],
password: ['',Validators.required],
repassword: ['',Validators.required],
age: ['',Validators.required],
state: ['',Validators.required],
country: ['',Validators.required]
});
}
tryGoogleLogin(){
this.authService.doGoogleLogin()
.then(res =>{
this.router.navigate(['/user']);
}, err => console.log(err)
)
}
tryRegister(value){
this.authService.doRegister(value)
.then(res => {
console.log(res);
this.fireservice.createUser(value);
this.errorMessage = "";
this.successMessage = "Your account has been created";
}, err => {
console.log(err);
this.errorMessage = err.message;
this.successMessage = "";
})
}
register(user: User){
}
update(user: User) {
this.fireservice.updateUser(user);
}
ngOnInit(){
console.log(this.countries);
}
}
И json:
{
"countries": [
{
"country": "Afghanistan",
"states": ["Badakhshan", "Badghis", "Baghlan", "Balkh", "Bamian", "Daykondi", "Farah", "Faryab", "Ghazni", "Ghowr", "Helmand", "Herat", "Jowzjan", "Kabul", "Kandahar", "Kapisa", "Khost", "Konar", "Kondoz", "Laghman", "Lowgar", "Nangarhar", "Nimruz", "Nurestan", "Oruzgan", "Paktia", "Paktika", "Panjshir", "Parvan", "Samangan", "Sar-e Pol", "Takhar", "Vardak", "Zabol"]
},
{
"country": "Albania",
"states": ["Berat", "Dibres", "Durres", "Elbasan", "Fier", "Gjirokastre", "Korce", "Kukes", "Lezhe", "Shkoder", "Tirane", "Vlore"]
},
{
"country": "Algeria",
"states": ["Adrar", "Ain Defla", "Ain Temouchent", "Alger", "Annaba", "Batna", "Bechar", "Bejaia", "Biskra", "Blida", "Bordj Bou Arreridj", "Bouira", "Boumerdes", "Chlef", "Constantine", "Djelfa", "El Bayadh", "El Oued", "El Tarf", "Ghardaia", "Guelma", "Illizi", "Jijel", "Khenchela", "Laghouat", "Muaskar", "Medea", "Mila", "Mostaganem", "M'Sila", "Naama", "Oran", "Ouargla", "Oum el Bouaghi", "Relizane", "Saida", "Setif", "Sidi Bel Abbes", "Skikda", "Souk Ahras", "Tamanghasset", "Tebessa", "Tiaret", "Tindouf", "Tipaza", "Tissemsilt", "Tizi Ouzou", "Tlemcen"]
},
{
"country": "Andorra",
"states": ["Andorra la Vella", "Canillo", "Encamp", "Escaldes-Engordany", "La Massana", "Ordino", "Sant Julia de Loria"]
},
{
"country": "Angola",
"states": ["Bengo", "Benguela", "Bie", "Cabinda", "Cuando Cubango", "Cuanza Norte", "Cuanza Sul", "Cunene", "Huambo", "Huila", "Luanda", "Lunda Norte", "Lunda Sul", "Malanje", "Moxico", "Namibe", "Uige", "Zaire"]
},
{
"country": "Antarctica",
"states": []
},
{
"country": "Antigua and Barbuda",
"states": ["Barbuda", "Redonda", "Saint George", "Saint John", "Saint Mary", "Saint Paul", "Saint Peter", "Saint Philip"]
},
{
"country": "Argentina",
"states": ["Buenos Aires", "Buenos Aires Capital", "Catamarca", "Chaco", "Chubut", "Cordoba", "Corrientes", "Entre Rios", "Formosa", "Jujuy", "La Pampa", "La Rioja", "Mendoza", "Misiones", "Neuquen", "Rio Negro", "Salta", "San Juan", "San Luis", "Santa Cruz", "Santa Fe", "Santiago del Estero", "Tierra del Fuego", "Tucuman"]
},
... и есть еще, но это то же самое.
Я пытался поместить {{country [2] .country}} в html, и он отлично работает, он показывает страну. И попробовал значение ng-option 90 разными способами, я не знаю, что делать.
Я потратил слишком много времени на это, и наверняка это легко решить, но я Мне нужно это знать, потому что я не хаха