Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 使用Angular2扫描条形码_Typescript_Angular_Barcode Scanner - Fatal编程技术网

Typescript 使用Angular2扫描条形码

Typescript 使用Angular2扫描条形码,typescript,angular,barcode-scanner,Typescript,Angular,Barcode Scanner,我想在asp.net 5/Angular2中开发一个应用程序,但我在扫描条形码时遇到问题 我的组件使用typeScript: @Component({ selector: 'barcode-scanner', templateUrl: 'app/scan.html', directives: [ROUTER_DIRECTIVES] }) export class ScanComponent implements OnInit { barcode: string;

我想在asp.net 5/Angular2中开发一个应用程序,但我在扫描条形码时遇到问题

我的组件使用typeScript:

@Component({
    selector: 'barcode-scanner',
    templateUrl: 'app/scan.html',
    directives: [ROUTER_DIRECTIVES]
})
export class ScanComponent implements OnInit {
    barcode: string;

    constructor() {}
    ngOnInit() { }

    onKey(event: any) {
        this.barcode = event.target.value;
    }
}
和我的html模板(scan.html):


我的应用程序标题
条形码:{{barcode}}

它正在工作,但只有当输入显示在屏幕上并聚焦时。 有没有一种方法可以通过隐藏输入来实现这一点?(我尝试了一个
input type=“hidden”
,还有一个
input type=“text”
,带有
display:none
样式属性,但在这两种情况下都不起作用


此外,是否可以捕获文档上的
按键
事件?而不是在指定的输入上?

通过将事件目标添加为前缀
target:event
目标
可以是
窗口
文档
正文

(window:keypress)="doSomething($event)"

好的,但是如果事件目标是一个
窗口
、一个
文档
或一个
正文
,我如何捕获扫描的条形码?我不知道扫描条形码时到底发生了什么,或者遇到了什么问题。我假设您只得到一系列键盘事件。只需将它们组合成一个字符串。是否有一些指示条形码扫描过程何时开始和何时结束?
(window:keypress)="doSomething($event)"