在typescript中定义常量(离子应用程序) [英] defining constants in typescript (ionic application)

查看:2940
本文介绍了在typescript中定义常量(离子应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Ionic应用程序中,我将常量定义为

In my Ionic application I am defining constants as

//constants.ts
export var CONSTANTS = {
 API_ENDPOINT: 'http://localhost:3000/'
};

并将其导入为

import {CONSTANTS} from '../../services/constants'; //the path is correct

但是我得到的错误CONSTANTS未在我导入的文件中定义..我在这里缺少什么?

However I get the error CONSTANTS not defined in the file where I am importing.. what am i missing here ?

推荐答案

这是你应该怎么做的:

// constants.ts
export const API_ENDPOINT= 'http://localhost:3000/';

并将其导入为:

import * as Constants from '../../services/constants';

你可以像这样访问它:

Constants.API_ENDPOINT;

这篇关于在typescript中定义常量(离子应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆