science-detail.component.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Component } from '@angular/core';
  2. // 引入服务
  3. import { ActivatedRoute } from '@angular/router';
  4. // 引入Parse第三方库
  5. import * as Parse from "parse"
  6. (Parse as any).serverURL = "http://metapunk.cn:9999/parse"
  7. Parse.initialize("dev")
  8. @Component({
  9. selector: 'app-science-detail',
  10. templateUrl: './science-detail.component.html',
  11. styleUrls: ['./science-detail.component.scss']
  12. })
  13. export class ScienceDetailComponent {
  14. //添加评论
  15. comments: string[] = [];
  16. comment: string = '';
  17. currentDate = new Date();
  18. addComment() {
  19. console.log(this.comment)
  20. if (this.comment.trim() !== '') {
  21. this.comments.push(this.comment);
  22. this.comment = '';
  23. }
  24. }
  25. //预设值变量
  26. science: Parse.Object | undefined;
  27. // 依赖注入
  28. constructor(private route: ActivatedRoute) {
  29. // 查询参数获取并赋值给this.science
  30. this.route.queryParams.subscribe(params => {
  31. this.getFoodInfoById(params["id"])
  32. })
  33. }
  34. async getFoodInfoById(id: string) {
  35. let query = new Parse.Query("PetScience")
  36. this.science = await query.get(id)
  37. }
  38. }