Created
March 7, 2023 15:10
-
-
Save sanjeevsubedi/b9556dacb505e69beb1069e4efb161a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Angular read only property decorator | |
* | |
*/ | |
export function readOnly(prototype: any, name: string) { | |
Object.defineProperty(prototype, name, { | |
writable: false, | |
}); | |
} | |
/** | |
* How to use it? | |
* | |
* export class AppComponent implements OnInit { | |
* @readOnly | |
* tax = 50; | |
* ............ | |
* } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment