ionic添加cordova插件-BarcodeScanner 2016-12-22 app ionic **BarcodeScanner** *打开相机自动扫描 条形码/二维码,返回数据。* ``` cordova plugin add phonegap-plugin-barcodescanner ``` ***方法(Methods)*** **scan()** *返回 对象 - 信息* **encode(type, text)** 参数 类型 说明 type Constant 编码类型(如:barcodescanner。编码。text_type) text String 编码所需的文本字符串 *返回 - 对象/编码文本* **Example** ``` module.controller('BarcodeCtrl', function($scope, $cordovaBarcodeScanner) { document.addEventListener("deviceready", function () { $cordovaBarcodeScanner .scan() .then(function(barcodeData) { // Success! Barcode data is here 扫描数据:barcodeData.text }, function(error) { // An error occurred }); // NOTE: encoding not functioning yet $cordovaBarcodeScanner .encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com") .then(function(success) { // Success! }, function(error) { // An error occurred }); }, false); }); ```