플랫폼
http://localhost:8100/?ionicplatform=android
프로젝트 생성
Run the following command to generate a new Ionic 2 application
ionic start ionic-todo blank --v2
페이지 생성
Run the following command to generate a new add-item page:
ionic g page AddItem
프로바이더 생성
Run the following command to generate a Data service:
ionic g provider Data
10 Minutes with Ionic 2: Using the Camera with Ionic Native
http://blog.ionic.io/10-minutes-with-ionic-2-using-the-camera-with-ionic-native/
http://www.gajotres.net/ionic-2-making-rest-http-requests-like-a-pro/
barcode scanner
https://www.thepolyglotdeveloper.com/2016/02/add-barcode-scanning-functionality-to-your-ionic-2-app/
book-barcode.html
<!--
Generated template for the BookBarcodePage page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-navbar *navbar>
<button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>BookBarcode</ion-title>
<ion-buttons end>
<button (click)="scan()">
<ion-icon name="add"></ion-icon>
scan
</button>
</ion-buttons>
</ion-navbar>
<ion-content padding class="book-barcode">
<ion-input [(ngModel)]="barcode" ></ion-input>
<ion-input [(ngModel)]="format" ></ion-input>
<img [src]="imgSrc" *ngIf="imgSrc"/>
<ion-input [(ngModel)]="title" ></ion-input>
<ion-input [(ngModel)]="subtitle" ></ion-input>
</ion-content>
book-barcode.ts
import {Page, NavController, Platform} from 'ionic-angular';
import {BarcodeScanner} from 'ionic-native';
import {Http} from 'angular2/http';
/*
Generated class for the BookBarcodePage page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Page({
templateUrl: 'build/pages/book-barcode/book-barcode.html',
})
export class BookBarcodePage {
public barcode;
public barcodeText;
public format;
public imgSrc;
public title;
public subtitle;
constructor(public nav: NavController, public platform: Platform, public http: Http) {
this.nav = nav;
this.platform = platform;
this.http = http;
}
scan() {
BarcodeScanner.scan().then((result) => {
this.barcode = result.text;
this.format = result.format;
let link = "http://www.kyobobook.co.kr/product/detailViewKor.laf?barcode=" + this.barcode;
this.http.get(link)
.subscribe(data => {
var parser = new DOMParser();
var doc = parser.parseFromString(data.text(), "text/html");
let imgSrc =
this.imgSrc = doc.querySelector('.cover a img').getAttribute('src');
this.title = doc.querySelector('.title strong').innerHTML.trim();
this.subtitle = doc.querySelector('.title .back strong').innerHTML.trim();
});
});
}
}
참고
'Programming > Android' 카테고리의 다른 글
[ionic] Promise resolve 으로 변경 (0) | 2016.05.17 |
---|---|
[ionic] open api 로 데이터 가져와서 적용하기 (0) | 2016.05.17 |
[ionic] template 비교 (0) | 2016.05.15 |
[ionic] visual studio code 에서 ionic2 코드를 열었을 때에 experimentalDecorators 관련 에러 (0) | 2016.05.14 |
[ionic] firebase 사용하기 (0) | 2016.05.13 |
댓글