简体   繁体   English

如何在 HTML 中查看我的 typeScript 的结果?

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

This is my HTML这是我的 HTML
*i changed all the code *我更改了所有代码

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

This is my .ts code the function teston() i dont know if it make sense这是我的 .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);
    
  }

}

This is my class Carte.ts这是我的课 Carte.ts

export class Carte {

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

        this.sorte = sor;
      

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

}

So what i want to do is to see in my HTML: Bob所以我想要做的是在我的 HTML 中看到: Bob
nothing seems to work am i missing something?似乎没有任何效果我错过了什么吗?

I think:我认为:

  1. Your test is not defined.您的测试未定义。 You need to create a new Carte type object.您需要创建一个新的 Carte 类型对象。
  2. In your carte class you are creating a public globa variable that's type is an Array, but in the function cart(sor), you overwrite it with a number.在您的 carte 类中,您正在创建一个类型为数组的公共全局变量,但在函数 carte(sor) 中,您用一个数字覆盖它。

Depending on your code, i think you want somethink like this:根据您的代码,我认为您想要这样的想法:

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

And in your ts file something like this:在你的 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);
  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM