首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角5:注射前运行结构体

角5:注射前运行结构体
EN

Stack Overflow用户
提问于 2018-03-20 14:33:07
回答 1查看 62关注 0票数 0

我有一个带有全局变量的文件:

代码语言:javascript
复制
@Injectable()
export class Globals {
  public baseURL:string;
  public loginURL:string;
  public proxyURL:string;
  public servicesURL:string;

  constructor(platformLocation: PlatformLocation) {
    this.baseURL = (platformLocation as any).location.href;
    this.loginURL = this.baseURL + 'rest/login';
    this.proxyURL = this.baseURL + 'rest/proxy';
    this.servicesURL = this.baseURL + 'rest/serviceRegistry';
  }
}

目前,我的API调用失败了,因为还没有设置变量。是否有一种方法只在构造函数运行时注入此服务,还是必须使用可观察的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-04 06:54:57

它本身并没有解决。我现在就这样用它:

代码语言:javascript
复制
@Injectable()
export class Globals {
  /** API URLS */
  public baseURL:string = '';
  public loginURL:string = 'rest/login';
  public proxyURL:string = 'rest/proxy';
  public servicesURL:string = 'rest/serviceRegistry';
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49387039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档