angular - 在另一个类角度4的模型中使用类对象?
问题描述
在我的项目中,我在模型部分有两个类,它们想要在另一个中使用其中一个的对象。其中一类是:
export class ConditionPerson {
marriedStatus: number;
familyNum: number;
pet: number;
describtion: string;
}
我想在下面的类中使用这个类的对象:
import {ConditionPerson } from './ConditionPerson ';
export class Property{
condition : ConditionPerson ;
}
现在我想在另一个类中使用条件属性:
import {Property} from '../models/Property';
export class AddPropertyComponent implements OnInit {
constructor(public:property: Property){}
if (this.addPropertyPage2.selectedStatus) {
if (this.addPropertyPage2.selectedStatus != null && typeof this.addPropertyPage2.selectedStatus === 'string') {
this.property.condition.marriedStatus= +this.addPropertyPage2.selectedVazTaahol;
}
else {
this.property.conditon.marriedStatus= this.addPropertyPage2.selectedStatus.id;
}
}
}
在 if 的 else 中,当它为 property.condition.marriedStatus 分配 id 时说: 无法设置未定义的属性“条件” 我应该怎么做才能解决这个问题?感谢您在高级方面的帮助。
解决方案
初始化属性对象
this.property = new property();
推荐阅读
- assembly - 您可以在 x86 中本地添加两个 64 位整数吗?
- android - 如何在 androidx 中访问 RecyclerView?
- jquery-file-upload - jQuery-File-Upload 失败,文件有点大
- azure - 如何使用 Azure 云服务运行多个可执行文件 - 函数应用程序?
- python - 如何在 Python 中使用海龟创建曲面细分
- python - Django信号在文件保存在服务器之前被触发?
- excel - 我可以根据用户表单中用户输入的公式创建方程吗?
- javascript - 使用 php 或 javascript 直接打印到打印机而不显示对话框
- node.js - 如何将外部请求的结果推送到 firebase 中的 realtimeDB?
- typescript - react-scripts-ts + vscode 断点