typescript 11. Les Services et l'injectiondedépendances。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 11. Les Services et l'injectiondedépendances。相关的知识,希望对你有一定的参考价值。

import { Injectable } from '@angular/core';
import { Pokemon } from './pokemon';
import { POKEMONS } from './mock-pokemons';

@Injectable()
export class PokemonsService {

    // Retourne tous les pokémons
    getPokemons(): Pokemon[] {
      return POKEMONS;
    }
    
    // Retourne le pokémon avec l'identifiant passé en paramètre
    getPokemon(id: number): Pokemon {
      let pokemons = this.getPokemons();
    
      for(let index = 0; index < pokemons.length; index++) {
        if(id === pokemons[index].id) {
          return pokemons[index];
        }
      }
    }
}

以上是关于typescript 11. Les Services et l'injectiondedépendances。的主要内容,如果未能解决你的问题,请参考以下文章