DEV Community

Faisal Ahmed
Faisal Ahmed

Posted on

Static Db Integration simple code

<div [innerHTML]="aboutUs?.description"></div>
Enter fullscreen mode Exit fullscreen mode
  • specific folder ts file
export class AboutUsComponent {
  public aboutUs: About = ABOUT_US_DB[0];

  private subReloadOne: Subscription;

  constructor(
    private _service : AboutUsService,
    private reloadService: ReloadService
  ) {}

  ngOnInit() {
    this.subReloadOne = this.reloadService.refreshData$.subscribe(async () => {
      this._getStaticData();
    });

    this._getStaticData();
  }

  private _getStaticData() {
    this.aboutUs = this._service.getAboutUs();
    console.log("aboutUs", this.aboutUs);

  }

  ngOnDestroy() {
    console.log('Page Destryed----------->');
  }
}
Enter fullscreen mode Exit fullscreen mode
  • service ts file
export class AboutUsService {
  private aboutUs: About[] = ABOUT_US_DB;

  constructor(private userService: UserService) {}

  /**
    getaboutUs()
   */

  getAboutUs() {
    let Data: About = null;
    Data = this.aboutUs?.find(
      (f: StaticDataInterface) =>
        f?.languageCulture === this.userService.getLanguageCulture()
    );
    return Data ? Data : null;
  }

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)