I am new to angular,
start adding a new component using ng generate component "name"
it works fine
but when i add the implements OnInit
the compiler start complains and gives
Class is using Angular features but is not decorated. Please add an explicit Angular decorator
this is my code below:
import { Component, Injectable, Input, OnInit } from '@angular/core'; import { User } from './user.model';
@Component({
selector: 'app-address-card',
templateUrl: './address-card.component.html',
styleUrls: ['./address-card.cpmponenet.css']
})
@Injectable()
export class AddressCardComponent implements OnInit{
user: any;
@Input('user') userDTO?: User;
ngOnInit(): void {
this.user = {
name: this.userDTO?.name,
title: this.userDTO?.designation,
address: this.userDTO?.address,
phone:this.userDTO?.phone
};
}
}
ts version : 4.8.2 angular version: 15.2.4 I have checked stack overflow but nothing helpful... any advice would be much appreciated.
EDIT1: just try to create a new component: the ts file look like this:
@Component({
selector: 'app-address-card',
templateUrl: './address-card.component.html',
styleUrls: ['./address-card.component.css']
})
export class AddressCardComponent implements OnInit{
ngOnInit(): void {
throw new Error('Method not implemented.');
}
}
with an error say under the "AddressCardComponent" says
Class is using Angular features but is not decorated. Please add an explicit Angular decorator.