首页 热点专区 小学知识 中学知识 出国留学 考研考公
您的当前位置:首页正文

ionic3 - 全局变量

来源:要发发知识网

全局变量的管理:
在app目录下新建app.config.ts文件,并新建类AppConfig,在类里面创建静态方法

export class AppConfig {
    //测试环境URL
    public static getDebugUrl() {
        return "http://192.168.1.117:8080/";
    }
    //生产环境URL
    public static getProdUrl() {
        return "http://192.168.1.117:8080/"
    }
    //获取当前环境URL
    public static getCurrentUrl() {
        return getDebugUrl();
    }
}

然后再需要使用全局变量的地方导入AppConfig

import { AppConfig } from './../../app/app.config';
显示全文