一、news.component.ts

  1. import { Component, OnInit } from '@angular/core';
  2. @Component({
  3. selector: 'app-news',
  4. templateUrl: './news.component.html',
  5. styleUrls: ['./news.component.css']
  6. })
  7. export class NewsComponent implements OnInit {
  8. title = "我是一个组件--ts";
  9. userInfo = {
  10. name: "张三",
  11. age: 18,
  12. };
  13. constructor() {}
  14. ngOnInit(): void {
  15. }
  16. }

二、news.component.html

  1. <p>{{title}}</p>
  2. <p>姓名:{{userInfo.name}}</p>
  3. <p>年龄:{{userInfo.age}}</p>

image.png
image.png