|  |  | 
          
            | สอบถามผู้รู้ชี้แนะหน่อยครับ Ionic 3 สแกน barcode ผ่าน http ไม่ได้
 มีไฟล์ .json ที่เก็บ data build ไปพร้อม ionic สามารถสแกนได้  พอเอาไฟล์ .json ที่เป็น data แยกออกแล้วรันผ่าน xampp หรือเอาขึ้น host จริง เรียกไม่ผ่าน  สแกนไม่ได้เลยครับ
 
 import { Component } from '@angular/core';
 import { NavController } from 'ionic-angular';
 import { BarcodeScanner } from '@ionic-native/barcode-scanner';
 import { Toast } from '@ionic-native/toast';
 import { DataServiceProvider } from '../../providers/data-service/data-service';
 
 
 @Component({
 selector: 'page-home',
 templateUrl: 'home.html'
 })
 export class HomePage {
 
 products: any = [];
 selectedProduct: any;
 productFound:boolean = false;
 
 constructor(public navCtrl: NavController,
 private barcodeScanner: BarcodeScanner,
 private toast: Toast,
 public dataService: DataServiceProvider) {
 this.dataService.getProducts()
 .subscribe((response)=> {
 this.products = response
 console.log(this.products);
 });
 }
 
 scan() {
 this.selectedProduct = {};
 this.barcodeScanner.scan().then((barcodeData) => {
 this.selectedProduct = this.products.find(product => product.sn === barcodeData.text);
 if(this.selectedProduct !== undefined) {
 this.productFound = true;
 console.log(this.selectedProduct);
 }else {
 this.selectedProduct = {};
 this.productFound = false;
 this.toast.show('ไม่พบบาร์โค้ด', '5000', 'center').subscribe(
 toast => {
 console.log(toast);
 }
 );
 }
 }, (err) => {
 this.toast.show(err, '5000', 'center').subscribe(
 toast => {
 console.log(toast);
 }
 );
 });
 }
 
 }
 
 
 
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 
 
 import { Injectable } from '@angular/core';
 import { HttpClient} from '@angular/common/http/';
 import 'rxjs/add/operator/map';
 
 
 /*
 Generated class for the DataServiceProvider provider.
 
 See https://angular.io/guide/dependency-injection for more info on providers
 and Angular DI.
 */
 @Injectable()
 export class DataServiceProvider {
 [x: string]: any;
 
 constructor(public http: HttpClient) {
 console.log('Hello DataServiceProvider Provider');
 }
 
 getProducts(){
 return this.http.get('http://domain.com/products.json')
 //.map((response:Response)=>response.json());
 
 }
 
 }
 
 
 
 Tag : Mobile, MySQL, Android, XAMPP
 
 
 |  
            | 
 ประวัติการแก้ไข
 2020-06-18 20:13:46
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2020-06-18 20:12:30 | By :
                          tum151 | View :
                          2009 | Reply :
                          1 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |