The below class has the following properties, which is auto-generated form swagger library
export class GetControlForPolicyDesignerView implements IGetControlForPolicyDesignerView {
control!: ControlDto;
referenceControl!: AuthorityProvisionListDto[] | undefined;
referenceCount!: number;
association!: boolean;
selected!: boolean;
statements!: StatementViewDto[] | undefined;
// ......
}
Interface
export interface IGetControlForPolicyDesignerView {
control: ControlDto;
referenceControl: AuthorityProvisionListDto[] | undefined;
referenceCount: number;
association: boolean;
selected: boolean;
statements: StatementViewDto[] | undefined;
}
In one of the class in Angular, I am assigning the value to the property below
Initialize the property at the beginning
selectedControl: GetControlForPolicyDesignerView = new GetControlForPolicyDesignerView();
Then assign the value to the property
this._guidanceBuilderDataService.selectedControlUpdate.pipe(takeUntil(this.unsubscribe)).subscribe((selectedControl) => {
this.selectedControl.referenceControl= selectedControl?.referenceControl;
this.selectedControl.referenceCount = selectedControl?.referenceCount;
this.selectedControl.statements = selectedControl?.statements;
});
Error
ERROR TypeError: Cannot assign to read only property 'referenceControl' of object '[object Object]'
at SafeSubscriber._next (guidance-designer.component.ts:223:99)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183:1)
at SafeSubscriber.next (Subscriber.js:122:1)
at Subscriber._next (Subscriber.js:72:1)
at Subscriber.next (Subscriber.js:49:1)
at TakeUntilSubscriber._next (Subscriber.js:72:1)
at TakeUntilSubscriber.next (Subscriber.js:49:1)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183:1)
at SafeSubscriber.next (Subscriber.js:122:1)
at Subscriber._next (Subscriber.js:72:1)
Tried code, but didn’t worked
(this.selectedControl.referenceControl as AuthorityProvisionListDto[]) = selectedControl?.referenceControl;