Ionic+ngCorodva携帯電話の振動機能を実現
2151 ワード
ngCordovaインストールインストールbower(ngCordovaのインストールが便利):npm install-g bower ngCordovaのインストール:bower install ngCordova ヒント:ENOGIT git is not installed or not in the PATHのエラーは、gitが見つからないため、次の必要があります. gitをインストールgit bashにより上記コマンド を実行する. gitがインストールされている場合は、git環境変数を構成できます.たとえば、C:Program Files(x 86)Gitbin;C:Program Files(x 86)Gitcmdをpathに追加し、構成が完了し、cmd を再起動します.
振動プラグインを取り付けます.プロジェクトファイル実行: appを編集する.js,バインドcontrollerとhtml tab-dashを編集する.html
小結
これで、振動機能の追加に成功し、本体テストに接続すればよい.ngCordovaの他のプラグインの使用方法は本稿とほぼ同じで、本書の使用方法を参考にすることができます.
振動プラグインを取り付けます.
// testApp( )\platforms\android\assets\www\plugins\
// cordova-plugin-vibration
// cordova plugin add org.apache.cordova.vibration ```
- ** :**
![ .png](http://upload-images.jianshu.io/upload_images/935378-1051a09d990ec22c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
- :
``` java
// testApp\platforms\android\AndroidManifest.xml
// G:\Ionic\testApp\platforms\android\res\xml\config.xml
// , build```
##
- controller.js **$cordovaVibration**
``` javascript
.controller('VibrationCtrl', function($scope, $cordovaVibration)
{
// startVib
$scope.startVib=function(){
// 1000ms
$cordovaVibration.vibrate(1000);
};
})
// ngCordova
angular.module('starter', ['ionic', 'ngCordova','starter.controllers', 'starter.services'])
//
.state('tab.dash',
{
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
// controller
controller: 'VibrationCtrl'
}
}
})
小結
これで、振動機能の追加に成功し、本体テストに接続すればよい.ngCordovaの他のプラグインの使用方法は本稿とほぼ同じで、本書の使用方法を参考にすることができます.