簡體   English   中英

屬性“ id”在類型“ void”上不存在

[英]Property 'id' does not exist on type 'void'

我試圖為我的角度應用程序的所有操作實施審核跟蹤,例如“刪除”,“ addUser”,“更新”等。我能夠通過“ posts-dashboard”中的“ post blog”功能成功實現此目的。 component.ts”,現在我嘗試使用“ student-user.component.ts”中的“ delete user”功能執行相同操作,但編譯器返回錯誤“ void”類型上不存在“ Property'id” '”

我嘗試將id定義為“ id:any;” 和'id ='''但我不認為這是解決方案。 錯誤不會消失。 審計跟蹤功能應該在控制台中打印輸出(審計跟蹤),並將審計跟蹤日志存儲在審計跟蹤模型下的數據庫中

這是我的student-user.component.ts。 尋找deleteStudent(value)函數...這就是我實現它的地方

import { Component, OnInit } from '@angular/core';
import { map, catchError} from 'rxjs/operators';
import {FirebaseService} from '../services/firebase.service';
import {Router} from '@angular/router';
import { AngularFirestore} from "angularfire2/firestore";
import { Observable } from 'rxjs';
import { AuditTrailService } from 'src/app/services/audit-trail/audit-trail.service';
import { AngularFireStorage } from '@angular/fire/storage';


@Component({
  selector: 'app-student-user',
  templateUrl: './student-user.component.html',
  styleUrls: ['./student-user.component.scss']
})

export class StudentUserComponent implements OnInit{
  students: any;
  students_data :any;
  public searchString: string;
  response: any;
  is_loading: any;
  ideas; any;
  term = '';
  //id: any[];


  constructor(
    public firebaseService: FirebaseService,
    private router: Router,
    public db: AngularFirestore,
    private storage: AngularFireStorage,
    public _auditTrailService:AuditTrailService
  ) { }


 ngOnInit() {

  this.getStudents()
  this.searchStudents(event)

}


getStudents() {
  this.students_data = this.db.collection('User', ref => ref.where('role', '==', 'student')).snapshotChanges().pipe(map(changes => {

  return changes.map(a => {
  const data: any = a.payload.doc.data();
  data.id = a.payload.doc.id;
  return data;
  });
  })
  );

  this.students_data.subscribe(
  res => {
  console.log(res);
  this.students = res;
  //this.blogs_snapshot = res;
  });

  }

  searchStudents(event){
    if (event.key === "Enter"){
      console.log(this.term)
      this.db.collection('User', ref => ref.where('full_name', '==', this.term)).valueChanges().subscribe(
      res => {
      this.response = res;
      console.log(this.response);

      this.ideas = res;
      this.is_loading = false;
        }
        );
    }
  }

  deleteStudent(value){
    this.db.collection('User').doc(value).delete().then( 
      res =>{
      console.log(res)
      this.students = res;
      const _audit_trail = {
        'action' : ' has deleted a student ',
        'object': res.id,
        'created_at': new Date(),
        'user':{
          'id': '4545454545454545454',
          'email':'daanyu@gmail.com' }
         } 
      console.log(_audit_trail)

      this._auditTrailService.createAuditTrailLog(_audit_trail)

    },

    err=>{
      console.log(err)
    }
    )
  }

} 

這是我的錯誤...

ERROR in src/app/student-user/student-user.component.ts(87,23): error TS2339: Property 'id' does not exist on type 'void'.

我使用Firebase作為數據庫,這是我期望在audit-trail模型下的數據庫中返回的內容:

操作“已刪除學生”在UTC + 3用戶於2019年7月22日下午5:49:33創建:電子郵件“ daanyu@gmail.com” id“ 4545454545454545454”

我以前沒有使用過Firebase,但是您的錯誤使我相信Firestore中的delete()方法不會返回成功響應,因為它暗示res的類型為void 您可以根據用例使用來自this.studentsthis.response的ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM