I'm creating new classes in Angular for data model.
I have created classes in new file and initialize them ins constructor
export class CreditPoliciesDetails {
private _fileName : string ="" ;
private _fileDate : string ="" ;
private _fileSize : string ="" ;
private _path : string="";
private _extention: string="";
constructor() {
this._fileDate="fileDate";
this._fileName="fileName";
this._fileSize="fileSize";
this._path="path";
this._extention="extension";
}
}
export class CreditPolicies {
private _document : CreditPoliciesDetails[];
private _directory: string
constructor (details: CreditPoliciesDetails[]) {
this._document = details;
this._directory="";
}
get category() {
return this._document
}
public details (detail) {
console.log(detail)
this._document= detail;
}
}
Then in my component ts file I declare new CreditPoliciesDetails array then pass it to files which is an array of type of CreditPolicies
details :CreditPoliciesDetails[] = new Array <CreditPoliciesDetails>();
files : CreditPolicies[] = new Array <CreditPolicies>(this.details);
In VS code I get a warning When I hover the argument of new Array <CreditPolicies>(this.details); Argument of type 'CreditPoliciesDetails[]' is not assignable to parameter of type 'CreditPolicies'.
Property '_document' is missing in type 'CreditPoliciesDetails[]'.
And when I console.log files and details I get empty array.
I'm expecting this format
[
{
"directory":"string",
"document":[{
"extension":"string",
"lastModifiedDate":"string",
"name":"string",
"path":"string",
"size":"0"
}]
}
]
detailsis empty array in your case. You're providing empty array asnew Arrayargument, while it's expected to be a number - and will result in emptyfilesarray too. I'd suggest to check how arrays work in JS, because they work in TS exactly the same way.