In my Angular 2 project, I have a specific object definition that includes properties for officeId, year, pageNumber, and pageSize.
export class MyFilter {
public officeId: string;
public year: number;
pageNumber: number;
pageSize: number;
public constructor() {
this.pageSize=10;
this.pageNumber=10;
this.year=2014;
this.officeId='abc';
}
}
I am trying to loop through the properties of this object using a for cycle:
let bean=new MyFilter();
for (const p in bean) {
if (bean.hasOwnProperty(p)) {
console.log(p + ': ' + bean[p]);
}
}
I simplified the code here to keep it focused on the issue. How can I effectively iterate over its properties in TypeScript? The current implementation does not output anything.