Angular 7直接打印收据
创始人
2024-10-17 06:00:29
0

要在Angular 7中直接打印收据,可以使用浏览器的打印功能。以下是一个示例代码,演示如何在Angular 7中实现打印功能:

  1. 创建一个名为print.component.ts的新组件。
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-print',
  templateUrl: './print.component.html',
  styleUrls: ['./print.component.css']
})
export class PrintComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

  printReceipt() {
    window.print();
  }

}
  1. print.component.html文件中,添加一个按钮并绑定到printReceipt()方法。

  1. 在需要展示的收据数据处,使用合适的HTML和CSS格式进行展示。

  2. 在需要打印的页面中,添加一个链接或按钮,导航到PrintComponent组件。

打印
  1. app.module.ts文件中,将PrintComponent添加到declarationsexports数组中。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';

import { AppComponent } from './app.component';
import { PrintComponent } from './print/print.component';

const routes: Routes = [
  { path: 'print', component: PrintComponent },
];

@NgModule({
  declarations: [
    AppComponent,
    PrintComponent
  ],
  imports: [
    BrowserModule,
    RouterModule.forRoot(routes)
  ],
  exports: [RouterModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  1. 运行应用程序,并导航到需要打印的页面。点击“打印”按钮将会触发printReceipt()方法,调用浏览器的打印功能。

这样就可以在Angular 7中实现直接打印收据的功能了。

相关内容

热门资讯

第八分钟辅助!西元红河辅助,真... 第八分钟辅助!西元红河辅助,真是是真的有辅助攻略(有挂方法)暗藏猫腻,小编详细说明西元红河辅助破解器...
9分钟辅助!奇迹陕西麻将辅助器... 9分钟辅助!奇迹陕西麻将辅助器,切实存在有辅助攻略(有挂方式)奇迹陕西麻将辅助器是不是有人用挂微扑克...
三分钟辅助!广西老友玩助手,真... 三分钟辅助!广西老友玩助手,真是存在有辅助教程(真是有挂)1、广西老友玩助手公共底牌简单,广西老友玩...
第1分钟辅助!闲来透视辅助器最... 第1分钟辅助!闲来透视辅助器最新版,一直存在有辅助app(确实有挂)闲来透视辅助器最新版能透视中分为...
第8分钟辅助!哈糖菠萝怎么挂,... 第8分钟辅助!哈糖菠萝怎么挂,真是是真的有辅助挂(确实有挂)1、上手简单,内置详细流程视频教学,新手...
第四分钟辅助!心悦填大坑辅助器... 第四分钟辅助!心悦填大坑辅助器,好像真的是有辅助方法(有挂教学)1、很好的工具软件,可以解锁游戏的心...
第4分钟辅助!陕麻圈黑科技,好... 第4分钟辅助!陕麻圈黑科技,好像是有辅助挂(有挂方略)陕麻圈黑科技脚本下载中分为三种模型:陕麻圈黑科...
第九分钟辅助!新九五有没有脚本... 第九分钟辅助!新九五有没有脚本,果然有辅助挂(新版有挂)1、进入到新九五有没有脚本是否有挂之后,能看...
第5分钟辅助!威信茶馆透视挂,... 第5分钟辅助!威信茶馆透视挂,一直有辅助插件(有挂讲解)威信茶馆透视挂辅助器是一种具有地方特色的麻将...
第9分钟辅助!蜀山四川破解版安... 第9分钟辅助!蜀山四川破解版安卓版辅助,原来有辅助脚本(有挂秘诀)蜀山四川破解版安卓版辅助破解侠是真...