Angular 2:从远程使用LOCAL_ID

时间:2017-03-22 11:57:13

标签: angular angular2-services

在我的角度应用中,我想为货币和其他管道设置LOCAL_ID。我从远程服务收到import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { LocaleService } from './locale.service'; import { LOCALE_ID } from '@angular/core'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent ], providers: [ LocaleService, { provide: LOCALE_ID, deps: [LocaleService], useFactory: (localeService: LocaleService) => { return localeService.getLocal().then(local => { console.log(local); return local; }) } }, ], bootstrap: [ AppComponent ] }) export class AppModule { } 。我需要将它设置为我的角度应用程序。我就是这样做的:

LocaleService

LocalService是我的服务从后端获取本地服务。这是我import { Injectable } from '@angular/core'; @Injectable() export class LocaleService { constructor() { } getLocal() { //return 'en-In'; return new Promise(resolve => { setTimeout(() => { resolve('en-In'); }, 3000); }); } } 的示例快照:

getLocal

挑战是,当async方法同步时,即当我对该值进行硬编码时,它可以正常工作,但是当我将其设为local时,它无效。我需要使用getLocal服务返回的def search(**parameters): # unpack the dictonary a = parameters['a'] dictonary = {'a': 0} foo = search(dictonary) 。不确定我错过了什么。正如here所解释的,我应该能够使用它。这是play的掠夺者。谢谢。

0 个答案:

没有答案