📜  typescript 从另一个文件导入变量 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:26.333000             🧑  作者: Mango

代码示例1
//in the first file backendUrls.ts or js
export const rooturl = 'http://127.0.0.1:8000';
export const cityListUrl = rooturl + '/api/city/'
export const all = {
    rooturl, cityListUrl
}

//in the component
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {backendUrls} from 'app/backendUrls'; //import the file with variables here

@Injectable()
export class cityGetService{
  constructor(private http: Http){}

  cityGet(){
    this.http.get(new backendUrls().cityListUrl) //use create new instance to use the variable
  }
}