Is there a way to automatically create a random 6-character string consisting of uppercase letters each time a form is submitted, and then assign this string to the 'code' parameter in the event array within the add-event.comonent.ts file?
The generated code should be made up of precisely 6 randomly selected uppercase letters.
Snippet from add-event.component.ts:-
export class AddEventComponent implements OnInit {
event: Event = {
code: '',
name:'',
password:'',
pollCat:''
}
constructor(private eventService : EventsService) { }
ngOnInit() {
}
onSubmit()
{
if(this.event.name !="" && this.event.password !="")
{
this.eventService.addEvent(this.event);
this.event.name = '';
this.event.password = '';
}
}
}
Snippet from events.service.ts:-
@Injectable({
providedIn: 'root'
})
export class EventsService {
eventsCollection : AngularFirestoreCollection<Event>;
events: Observable<Event[]>;
constructor(public afs: AngularFirestore) {
this.eventsCollection = this.afs.collection<Event>('Events');
this.events = this.eventsCollection.snapshotChanges().pipe(
map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Event;
data.id = a.payload.doc.id;
return data;
})
}));
}
getEvents()
{
return this.events;
}
addEvent(event: Event)
{
this.eventsCollection.add(event);
}
}