Data in components

To better understand the importance of services and DI, let's create a simple app with a component that shows a list of user comments. Once you have an app created, you can run the following command to generate the required component:

ng g component comment-list

Update the component's code with the following snippet:

import { Component, OnInit } from '@angular/core';@Component({  selector: 'app-comment-list',  templateUrl: './comment-list.component.html',  styleUrls: ['./comment-list.component.css']})export class CommentListComponent implements OnInit {  comments: Array<any>  constructor() { }  ngOnInit() {    this.comments = [      {        author: 'solomon',        content: `TypeScript + Angular is amazing`      },      {        author: 'lorna', content: `TypeScript ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.