I create a component in angular 6 with sample on how to implement decorators. So, I create a custom decorator called @Course and set a value there, named Angular 6. Now, how to get that value in my component's constructor?
I want to log the "Angular 6" value to my constructor. How's that possible?
Here is my code. Work's fine. I've got the value. But got an error in 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() {
}
}