In this scenario, we have an abstract class with an implemented method that the HomeComponent extends, and a service with the same code that we inject into the component. Are there any differences in our case? If so, what are the differences? If not, when should we use an abstract class versus a service?
abstract class Base {
name: string = "";
getName(){
return this.name;
}
}
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent extends Base implements OnInit {
}
vs
@Injectable()
export class BaseService {
name: string = "";
getName(){
return this.name;
}
}
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
providers: [BaseService]
})
export class HomeComponent implements OnInit {
constructor(private baseService: BaseService) {}
}