我如何在 HTML 中查看我的打字稿的结果?

How can i see the result form my typeScript in the HTML?

这是我的HTML
*我更改了所有代码

<div class="testCenter">
    <h1>{{teston()}}</h1>
</div>

这是我的 .ts 代码 函数 teston() 我不知道它是否有意义

import { Component, OnInit } from '@angular/core';
import { Carte } from '../mesClass/Carte'; // importation de la class Carte

@Component({
  selector: 'app-gestion-poker',
  templateUrl: './gestion-poker.component.html',
  styleUrls: ['./gestion-poker.component.css']
})
export class GestionPokerComponent implements OnInit {

  test:Carte;

  constructor() { }

  ngOnInit(): void {
  }


  teston(){

  return this.test.carte(1);
    
  }

}

这是我的classCarte.ts

export class Carte {

    // Attributs
    sorte = new Array;
    
    carte(sor){

        this.sorte = sor;
      

        sor = ["hello","Bob"];
       
        
    }

}

所以我想做的是在我的 HTML 中看到: 鲍勃
似乎没有任何效果是我遗漏了什么吗?

我认为:

  1. 您的测试未定义。您需要创建一个新的 Carte 类型对象。
  2. 在您的 carte class 中,您正在创建一个 public 类型为数组的 globa 变量,但在函数 cart(sor) 中,您用数字覆盖它。

根据您的代码,我认为您需要这样的想法:

export class Carte {
    sorte: Array<string> = ['hello', 'Bob'];
    
    carte(sor){
      return this.sorte[sor]  
    }
}

在你的 ts 文件中是这样的:

import { Component, OnInit } from '@angular/core';
import { Carte } from '../mesClass/Carte'; // importation de la class Carte

@Component({
  selector: 'app-gestion-poker',
  templateUrl: './gestion-poker.component.html',
  styleUrls: ['./gestion-poker.component.css']
})
export class GestionPokerComponent implements OnInit {

  test:Carte;

  constructor() { }

  ngOnInit(): void {
     this.test = new Carte();
  }


  teston(){
     return this.test.carte(1);
  }

}