0
아래의 코드를 사용하여 USB 포트에 연결된 장치를 볼 수 있습니다. 명령 프롬프트에서 'ng serve'명령을 실행할 때 컴파일 타임에 "속성 usb가 유형 네비게이터에 없습니다"오류가 발생합니다.속성 "usb"가 angular2 typescript 프로젝트의 "Navigator"유형에 존재하지 않습니다.
interface Navigator {
usb: {
getDevices(): any[];
}
}
이것은 컴파일 시간 오류를 해결합니다 (그러나 런타임 오류가 발생합니다 :
당신이navigator.usb
가 있는지 확인하는 경우
ngOnInit() {
async() => {
let devices = await navigator.usb.getDevices();
devices.forEach(device => {
// Add |device| to the UI.
console.log(device);
});
}
}