Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Angular Frontend 07: Dummy Daten laden

02.02.2023 (πŸ‘3074)


 

 

Mit dem folgenden Code werden beim Start der Anwendung die Daten vom Service geladen  und in der Console angezeigt

  //*add dummy data

  articles: Article[]=[];  //empty start

  constructor(private articlesService:ArticlesService){}

  ngOnInit():void{

    this.articles=this.articlesService.getArticles();

    console.log(this.articles);

  }

Ein Bild, das Text, Screenshot, Computer, drinnen enthΓ€lt.

Automatisch generierte Beschreibung

Dummy laden

App.components.ts

import { Component } from '@angular/core';

import { Article } from './models/article';

import { ArticlesService } from './services/articles.service';

 

@Component({

  selector: 'app-root',

  templateUrl: './app.component.html',

  styleUrls: ['./app.component.css']

})

export class AppComponent {

  title = 'CodeDocu_Frontend';

 

  //*add dummy data

  articles: Article[]=[];  //empty start

  constructor(private articlesService:ArticlesService){}

  ngOnInit():void{

    this.articles=this.articlesService.getArticles();

    console.log(this.articles);

  }

}