我想将模块配置从一个模块传播到另一个模块。我发现这很难详细解释,因此我将举一个例子。
我有一个类似的模块:
@NgModule({
declarations: [
ButtonComponent,
TranslatePipe,
],
imports: [
CommonModule,
],
exports: [
ButtonComponent,
],
})
export class ButtonModule {
static withConfig(config: ButtonModuleConfig): ModuleWithProviders {
return {
ngModule: ButtonModule,
providers: [
{
provide: TranslateService,
useClass: config.translateService,
},
],
};
}
}
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情是另一个模块:
@NgModule({
declarations: [
PageComponent,
],
imports: [
CommonModule,
ButtonModule, // the one defined above without overriding the TranslateService
],
exports: [
PageComponent,
],
})
export class PageModule {
static withConfig(config: PageModuleConfig): ??? {
return {
ngModule: PageModule, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用自定义MultipartEntity也从Android应用程序上传图像,该自定义也会更新ProgressDialog(这也是我使用已弃用的原因MultipartEntity).
相关的Java代码:
File file = new File(imgPath);
HttpPost post = new HttpPost("http://" + SERVER + "/upload");
MultipartEntity entity = new MyMultipartEntity(new MyMultipartEntity.ProgressListener()
{
public void transferred(long num)
{
publishProgress((int) ((num / (float) totalSize) * 100));
Log.d("DEBUG", num + " - " + totalSize);
}
});
ContentBody cbFile = new FileBody(file, "image/jpeg");
entity.addPart("source", cbFile);
totalSize = entity.getContentLength();
post.setEntity(entity);
HttpResponse response = client.execute(post);
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode == HttpStatus.SC_OK){
String fullRes = EntityUtils.toString(response.getEntity());
Log.d("DEBUG", fullRes); …Run Code Online (Sandbox Code Playgroud)