(a) add property at component.ts
export class UserAddUpdateComponent implements OnInit {
readOnly :boolean = this.data != null ? true:false;
(b) in component.html
<input
formControlName="userName"
matTooltip="Enter User Name"
matInput
placeholder="User Name"
required
[readonly]="this.readOnly"
/>