Before we start working with Ionic built-in decorators, we will quickly get an understanding of what decorators are and how they can make our life easy.
In simple words, a decorator is a function that takes a class and extend its behavior without actually modifying it.
For instance, if we had a person class and we want to add more information about the person to the class, such as age and gender, we can do so quite easily.
The following is an example of how we can write our own decorator in TypeScript:
@MoreInfo({
age: 5,
gender: 'male'
})
class Person {
constructor(private firstName, private lastName) {}
}
And the MoreInfo decorator would look something like this:
function MoreInfo(config) {
return function (target) {
Object.defineProperty(target.prototype, 'age', {value: () => config.age});
Object.defineProperty(target.prototype, 'gender&apos...