错误TypeError:无法读取此文件中null的属性name
:
import {Component, Input, OnInit} from '@angular/core';
import {Project} from '../../project';
import {Candidate} from '../../../candidates/candidate';
import {User} from '../../../../shared/services/user';
import {Client} from '../../../clients/client';
import {CandidatesService} from '../../../candidates/candidates.service';
import {ProjectsService} from '../../projects.service';
import {ClientService} from '../../../clients/client.service';
import {Job} from '../../../../shared/services/job';
import {UsersService} from '../../../../shared/services/users.service';
import {JobsService} from '../../../../shared/services/job.service';
@Component({
selector: 'app-all-projects-add',
templateUrl: './all-projects-add.component.html',
styleUrls: ['./all-projects-add.component.scss']
})
export class AllProjectsAddComponent implements OnInit {
@Input() cValue;
@Input() dValue;
project: Project;
users: User[];
candidates: Candidate[];
clients: Client[];
jobs: Job[];
success = false;
failure = false;
constructor(private projectsService: ProjectsService,
private userService: UsersService,
private clientService: ClientService,
private candidatesService: CandidatesService,
private jobsService: JobsService) {
this.userService.getItemsList().subscribe(users => this.users = users);
this.clientService.getItemsList().subscribe(clients => this.clients = clients);
// this.candidatesService.getItemsList().subscribe(candidates => this.candidates = candidates);
this.jobsService.getItemsList().subscribe(jobs => this.jobs = jobs);
this.project = new Project();
}
ngOnInit() {
}
validation(): boolean {
if (!this.project.candidatesNo) {
return false
}
return true;
}
addProject() {
console.log(this.project);
if (this.validation()) {
this.clientService.getItem(this.project.client_key).subscribe(client => {
this.userService.getItem(this.project.user_key).subscribe(user => {
this.project.user_name = user.name;
this.project.city = user.city;
// we do this for ng2-smart-table
this.project.startTime = this.project.startTime.year + '/' +
this.project.startTime.month + '/' +
this.project.startTime.day;
this.project.endTime = this.project.endTime.year + '/' +
this.project.endTime.month + '/' +
this.project.endTime.day;
console.log('Project added successfully...');
this.success = true;
this.projectsService.createItem(this.project);
setTimeout(function () {
this.success = false;
this.dValue('Cross click');
this.project = new Project();
}.bind(this), 1500);
})
})
} else {
this.failure = true;
console.log('Error adding new project...');
setTimeout(function () {
this.failure = false;
}.bind(this), 1500);
}
}
}
这是Angular4,Angularfire2和firebase。我在这里也让您查看user.ts文件。
// Roles interface
export interface Roles {
recruiter: boolean;
client: boolean;
admin: boolean;
}
// User class
export class User {
$key: string;
$key2: string;
email: string;
name: string;
displayName: string;
city: string;
profile = false;
admin = true;
roles: Roles;
uid: string;
constructor() {
this.name = '';
this.city = '';
this.displayName = '';
}
}
当我尝试将新项目添加到列表中时,出现此错误,并且不明白为什么。我的应用程序上有一个名为event的相似实体,具有与用户auth.uid
绑定的相同模型,并且效果很好。这是一个问题。如果有人可以解释为什么它不起作用,请给我真正的感谢。
“错误TypeError:无法读取null的属性'名称'”