community.page.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Component, OnInit } from '@angular/core';
  2. import { IonButton, IonCard, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonInput, IonItem, IonList, IonTitle, IonToolbar } from '@ionic/angular/standalone';
  3. import { IonCardContent,IonLabel } from '@ionic/angular/standalone';
  4. import { FormsModule } from '@angular/forms';
  5. import { CommonModule } from '@angular/common';
  6. @Component({
  7. selector: 'app-community',
  8. templateUrl: './community.page.html',
  9. styleUrls: ['./community.page.scss'],
  10. standalone: true,
  11. imports: [IonHeader,IonToolbar,IonTitle,IonContent,IonList,IonCard,IonCardHeader,
  12. IonCardTitle,IonCardSubtitle,IonItem,IonInput,IonButton,IonIcon,IonCardContent,
  13. FormsModule,CommonModule,IonLabel
  14. ],
  15. })
  16. export class CommunityPage implements OnInit {
  17. comments: { username: string; date: Date; text: string }[] = [];
  18. newComment: string = '';
  19. constructor() {
  20. this.comments = [
  21. { username: '用户1', date: new Date(), text: '这件衣服真好看!' },
  22. { username: '用户2', date: new Date(), text: '我也想要一件!' },
  23. ];
  24. }
  25. addComment() {
  26. if (this.newComment.trim()) {
  27. const newCommentObj = {
  28. username: '当前用户', // 可以替换为实际的用户名
  29. date: new Date(),
  30. text: this.newComment,
  31. };
  32. this.comments.push(newCommentObj);
  33. this.newComment = ''; // 清空输入框
  34. }
  35. }
  36. ngOnInit() {
  37. }
  38. }