我正在为我的angular2 Web 应用程序构建一个页面,用户可以从列表中选择客户并打印信件以邮寄给他们。这些信件已上传PDFs并存储varbinary在数据库中。
在进行多项选择的情况下,我只是附加字节[],以便用户打印一份包含要发送给客户的所有信件的文档。
我能够从 API 成功提取 blob 并使用内容类型返回它,application-pdf但我不知道如何处理它。
这是我的 Angular2 组件 API 调用:
this.printQueueService.getPrintContent(printRequests) //customers to receive letters
.subscribe((data: Blob) => {
var element: HTMLIFrameElement = <HTMLIFrameElement>document.getElementById('printFile');
element.innerText = data + ""; //what do I do with the blob?
element.contentWindow.print();
});
Run Code Online (Sandbox Code Playgroud)
HTML 元素:
<iframe id="printFile" style="display:none"></iframe>
Run Code Online (Sandbox Code Playgroud)
我知道我可以只下载 PDF 并提示用户使用 PDF 查看器进行打印,但我不想强迫用户执行额外的步骤。
我也不想尝试在浏览器中渲染 PDF 并打印,因为它假设用户拥有适当的插件并且浏览器支持它。
在浏览器中打印 blob 有哪些选项?
我正在努力使用路线保护来保护我的Angular应用程序的前端.在过去与他们合作并在线研究时,为路由添加多个防护要求所有这些防护都返回true以允许访问.
但是如果我只想让一个返回true以允许访问呢?(比如||而不是&&)
例如,我的路线保护在用户的令牌中查找某些角色:
@Injectable()
export class ActiveRoleGuard implements CanActivate {
constructor(private sessionService: SessionService, private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let token = this.sessionService.getToken();
if (!token) {
return false;
}
if (token.role.toLowerCase().indexOf("active") < 0) {
this.router.navigate(["/issue"]);
return false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
和
@Injectable()
export class AdminRoleGuard implements CanActivate {
constructor(private sessionService: SessionService, private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let token = this.appSessionService.getToken(); …Run Code Online (Sandbox Code Playgroud) roles typescript angular-routing angular angular-route-guards
我正在构建一个Angular2服务来记录存储在ILog对象中的某些事件,并将它们发送到API以存储在数据库中.
我的日志服务非常简单:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { EnvironmentModule } from "../environment";
import { ILog } from "./log";
@Injectable()
export class LogService {
constructor(private _http: Http, private environment: EnvironmentModule) { }
postLog(log: ILog): void {
this.json = this.convertToJSON(log);
this._http.post(this.environment.getWebApiUri() + 'api/Log/PostLog/', log, {})
.subscribe(
() => console.log('Success')
); //goes to localhost:3304/WebAPI/Log/PostLog/, returns 404 not found
}
}
Run Code Online (Sandbox Code Playgroud)
它调用一个WebAPI控制器,将数据传递给要处理的服务:
[RoutePrefix("api/Log")]
public class LogController : ApiController
{
private ILogService _LogService;
public LogController() : this(new …Run Code Online (Sandbox Code Playgroud)