Hiển thị các bài đăng có nhãn extend base component. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn extend base component. Hiển thị tất cả bài đăng

Angular extend base component

Source: https://stackoverflow.com/questions/49320759/angular-4-extend-base-component

Since base class doesn't need to be instantiated on its own, it's abstract class and doesn't need to have @Component decorator.
If it has dependencies, and there's a chance that constructor will be omitted in child classes and inherited, base class should have @Injectable decorator:
@Injectable()
export abstract class BaseComponent implements OnInit {
  constructor(public dep: Dep) {}

  ngOnInit() {}
}

@Component({
  selector: 'app-child',
  templateUrl: './child.component.html',
  styleUrls: ['./child.component.css']
})
export class ChildComponent extends BaseComponent {
  // dummy constructor can be omitted
/*
  constructor(dep: Dep) {
    super(dep);
  }
*/
}

anti-pattern là gì

  Trong công nghệ và lập trình, Anti-pattern (mẫu phản diện) là những giải pháp bề ngoài có vẻ hiệu quả để giải quyết một vấn đề phổ biến, ...