小编Lou*_*cký的帖子

PDF Blob没有显示内容,Angular 2

我的问题非常类似于这个PDF Blob - 弹出窗口没有显示内容,但我使用的是Angular 2.问题的回答是将responseType设置为arrayBuffer,但它在Angular 2中不起作用,错误是reponseType没有存在于RequestOptionsArgs类型中.我也尝试通过BrowserXhr扩展它,但仍然不起作用(https://github.com/angular/http/issues/83).

我的代码是:

createPDF(customerServiceId: string) {
   console.log("Sending GET on " + this.getPDFUrl + "/" + customerServiceId);

   this._http.get(this.getPDFUrl + '/' + customerServiceId).subscribe(
       (data) => {
            this.handleResponse(data);
         });
}
Run Code Online (Sandbox Code Playgroud)

而handleResponse方法:

handleResponse(data: any) {
     console.log("[Receipt service] GET PDF byte array " + JSON.stringify(data));

     var file = new Blob([data._body], { type: 'application/pdf' });            
     var fileURL = URL.createObjectURL(file);
     window.open(fileURL);
 }
Run Code Online (Sandbox Code Playgroud)

我也尝试从FileSaver.js中保存方法,但是同样的问题,pdf打开,但内容不显示.谢谢

pdf blob bytearray angular

15
推荐指数
2
解决办法
4万
查看次数

浏览器语言检测

我需要在我的Angular2应用程序中检测浏览器语言.基于这种语言,我需要发送请求(到后端的REST API),我的变量的本地化和ID,我需要翻译.之后我收到了翻译变量的回复.

因此,应用程序工作流程是检测浏览器语言,例如,确定en-US后,我将向后端发送请求,为en-US提供ID为1,2,3,4,5的变量.回应是{{id:1, var:pay}, {id:1, var:title}}等等

那么如何使用Angular2(使用typescript开发)浏览器语言进行检测?

translate language-detection typescript angular

8
推荐指数
1
解决办法
2万
查看次数

前端无法到达单独的 docker 容器中的后端端口

我的前端应用程序位于 NGINX 后面,它在 docker 容器中提供静态前端文件(用 Angular 编写),通信端口为 80:80。

我的后端应用程序是 NestJS,它在另一个 Docker 容器中的端口 localhost:3000 上提供数据。

使用 docker-compose up 启动应用程序,但我的前端无法到达后端 - 得到 502,坏 GW。

该问题是由 nginx 或 docker-compose.yml 或两者的设置引起的?

Dockerfile 前端:

FROM node:latest AS builder

WORKDIR /app
COPY . .
ARG configuration=production
RUN npm install && npm run build.prod

FROM nginx:latest
LABEL version="1.0"

COPY nginx.conf /etc/nginx/nginx.conf

WORKDIR /usr/share/nginx/html
COPY --from=builder /app/dist/frontend/ .
Run Code Online (Sandbox Code Playgroud)

Dockerfile 后端:

FROM node:10 AS builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run …
Run Code Online (Sandbox Code Playgroud)

containers docker docker-compose angular nestjs

3
推荐指数
1
解决办法
4864
查看次数

Components内的routerLink不会生成内容

我正在尝试从组件生成html内容很多时间,但是这个组件是从AppCompoment生成的.所以我想用routerLink从组件生成内容.我将在下面展示这个例子.知道我使用DeborahK从pluralsight.com教程获得的这个解决方案,我的源代码与此https://github.com/DeborahK/Angular2-GettingStarted/blob/master/APM - Final 相同.好的,让我们解释一下我的代码.

我有主index.html

<html>
<head>
    <base href="/">
    <title></title>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <!--<script src="node_modules/es6-shim/es6-shim.js"></script>-->
    <script src="node_modules/systemjs/dist/system-polyfills.js"></script>

    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>

    <!-- if NOT included, does not work in IE-->
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>

    <!--Http module-->
    <script src="node_modules/angular2/bundles/http.dev.js"></script>

    <!-- Routing -->
    <script src="node_modules/angular2/bundles/router.dev.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support …
Run Code Online (Sandbox Code Playgroud)

html router angularjs angular2-routing angular

2
推荐指数
1
解决办法
2211
查看次数