首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >属性'id‘在类型'void’上不存在

属性'id‘在类型'void’上不存在
EN

Stack Overflow用户
提问于 2019-07-23 15:54:34
回答 1查看 1K关注 0票数 1

我正在尝试为我的angular应用程序的所有操作实现一个审计跟踪,比如'delete‘'addUser’'update‘等。我能够用“post blog”函数成功地实现这一点,该函数位于“post-dashboard.Component.ts”中,现在我正尝试使用'delete user’函数执行相同的操作,但编译器返回错误“属性'id‘不存在于类型'void'”。

我尝试将id定义为'id: any;‘和'id =’‘,但我不认为这是解决方案。错误不会消失。审计跟踪功能应该在控制台中打印输出(审计跟踪),并在审计跟踪模型下将审计跟踪日志存储在数据库中

这是我的学生-user.Component.ts。注意deleteStudent(value)函数……这就是我要实现它的地方

代码语言:javascript
复制
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)
    }
    )
  }

} 

这是我的错误。

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

我正在使用Firebase作为我的数据库,这是我期望在我的审计跟踪模型下的数据库中返回的内容:

操作“已删除学生”电子邮件2019年7月22日下午5:49:33 UTC+3用户: created_at "daanyu@gmail.com“id "4545454545454545454”

EN

回答 1

Stack Overflow用户

发布于 2019-07-23 17:05:17

我以前没有使用过Firebase,但是你的错误让我相信Firestore中的delete()方法不会返回成功响应,因为它暗示resvoid类型的。您可以根据自己的用例使用this.studentsthis.response中的id。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57159293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档