I've recently developed an Angular 6 component that showcases the implementation of decorators. One of the decorators I've created is called @Course, with the value 'Angular 6' assigned to it. Now, I'm trying to figure out how to retrieve this value in the constructor of my component.
My goal is to log the value 'Angular 6' in the constructor. Is there a way to achieve this?
Although my code seems to be working fine and I am able to retrieve the value, I encountered an error in the command line:
ERROR in src/app/components/decorators/decorators.component.ts(19,22): error TS2339: Property
'course' does not exist on type 'DecoratorsComponent'.
import { Component, OnInit } from '@angular/core';
function Course(target) {
Object.defineProperty(target.prototype, 'course', {
value: () => "Angular 6"
})
}
@Course
@Component({
selector: 'app-decorators',
templateUrl: './decorators.component.html',
styleUrls: ['./decorators.component.scss']
})
export class DecoratorsComponent implements OnInit {
constructor() {
console.log(this.course());
}
ngOnInit() {
}
}