我想在每次提交表单时生成一个格式为“ZXCVBN”的随机字符串,并分配给 add-event.comonent.ts 文件中事件数组的“code”参数。我该怎么做?
代码必须正好包含 6 个大写随机字母。
添加-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 = '';
}
}
}
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);
}
}
慕桂英546537
MMTTMM
呼啦一阵风
12345678_0001
相关分类