我有一個angularJS應用程序。我想要使用ngCordova($ cordovaNetwork)的插件啓用ngCordova模塊。但我無法成功將ngCordova添加到我的項目中。 我的角度項目是由約曼創建:無法在angularJS上添加cordova插件
$ mkdir myFolderProjectAngular; cd myFolderProjectAngular
$ yo angular
然後,我添加ngCordova:
$ bower install --save ngCordova
bower ngCordova#~0.1.23-alpha cached git://github.com/driftyco/ng-cordova.git#0.1.23-alpha
bower ngCordova#~0.1.23-alpha validate 0.1.23-alpha against git://github.com/driftyco/ng-cordova.git#~0.1.23-alpha
bower ngCordova#* cached git://github.com/driftyco/ng-cordova.git#0.1.23-alpha
bower ngCordova#* validate 0.1.23-alpha against git://github.com/driftyco/ng-cordova.git#*
bower ngCordova#~0.1.23-alpha install ngCordova#0.1.23-alpha
我bower.json自動更新:
{
"name": "test-network",
"version": "0.0.0",
"dependencies": {
"angular": "^1.4.0",
"bootstrap": "^3.2.0",
"angular-route": "^1.4.0",
"ngCordova": "~0.1.23-alpha"
},
"devDependencies": {
"angular-mocks": "^1.4.0"
},
"appPath": "app",
"moduleName": "testNetworkApp",
"overrides": {
"bootstrap": {
"main": [
"less/bootstrap.less",
"dist/css/bootstrap.css",
"dist/js/bootstrap.js"
]
}
}
}
我手動添加兩行index.html:
<script src="/lib/ngCordova/dist/ng-cordova.js"></script>
<script src="/cordova.js"></script>
當我運行「咕嚕服務」來測試,我的index.html編輯,前兩行是disapear和替換:
<script src="bower_components/ngCordova/dist/ng-cordova.js"></script>
當我嘗試添加科爾多瓦插件,我有錯誤:
Error: Current working directory is not a Cordova-based project.
我不明白這個問題。
這是我的文件夾項目
.
├── app/
├── bower_components
│ ├── angular/
│ ├── angular-mocks/
│ ├── angular-route/
│ ├── bootstrap/
│ ├── jquery/
│ └── ngCordova
│ ├── bower.json
│ ├── CHANGELOG.md
│ ├── dist/
│ │ ├── ng-cordova.js
│ │ ├── ng-cordova.min.js
│ │ ├── ng-cordova-mocks.js
│ │ └── ng-cordova-mocks.min.js
│ ├── LICENSE
│ ├── package.json
│ └── README.md
├── bower.json
├── Gruntfile.js
├── node_modules/
├── package.json
├── README.md
└── test/
編輯: 我通過改變文件夾解決了我的第一個問題。 我首先創建一個全球性的文件夾科爾多瓦
cordova create myApp com.organisation.myapp MyApp
在此文件夾中創建角項目
yo angular MyApp
後,我可以添加鮑爾和ngCordova添加科爾多瓦插件。
我的問題,我不能使用插件的功能。在app.js,我有:
angular.module('myAppApp', ['ngRoute', 'ngCordova' ]) ...
和main.js,我有例如(使用Toast插件):
angular.module('myAppApp')
.controller('MainCtrl', function ($scope, $cordovaToast) {
console.log(">");
$cordovaToast.show('Here is a message', 'long', 'center')
.then(function(success) {
// success
}, function (error) {
// error
});
console.log("<")
});
main.js:12:4 Error: $window.plugins is undefined [email protected]http://localhost:9000/bower_components/ngCordova/dist/ng-cordova.js:6593:9 @http://localhost:9000/scripts/controllers/main.js:13:4 [email protected]http://localhost:9000/bower_components/angular/angular.js:4523:14 [email protected]http://localhost:9000/bower_components/angular/angular.js:4531:27 $ControllerProvider/this.$gethttp://localhost:9000/bower_components/angular/angular.js:9197:18 ngViewFillContentFactory/<[email protected]http://localhost:9000/bower_components/angular-route/angular-route.js:977:26 [email protected]http://localhost:9000/bower_components/angular/angular.js:8841:9 [email protected]http://localhost:9000/bower_components/angular/angular.js:8335:1 [email protected]http://localhost:9000/bower_components/angular/angular.js:7731:13 [email protected]http://localhost:9000/bower_components/angular/angular.js:7611:30 createBoundTranscludeFn/[email protected]http://localhost:9000/bower_components/angular/angular.js:7749:1 [email protected]http://localhost:9000/bower_components/angular/angular.js:8362:18 [email protected]http://localhost:9000/bower_components/angular-route/angular-route.js:935:25 $RootScopeProvider/this.$gethttp://localhost:9000/bower_components/angular/angular.js:16374:15 commitRoute/<@http://localhost:9000/bower_components/angular-route/angular-route.js:619:15 [email protected]http://localhost:9000/bower_components/angular/angular.js:14792:28 scheduleProcessQueue/<@http://localhost:9000/bower_components/angular/angular.js:14808:27 $RootScopeProvider/this.$gethttp://localhost:9000/bower_components/angular/angular.js:16052:16 $RootScopeProvider/this.$gethttp://localhost:9000/bower_components/angular/angular.js:15870:15 $RootScopeProvider/this.$gethttp://localhost:9000/bower_components/angular/angular.js:16160:13 [email protected]http://localhost:9000/bower_components/angular/angular.js:10589:36 [email protected]http://localhost:9000/bower_components/angular/angular.js:10787:7 [email protected]http://localhost:9000/bower_components/angular/angular.js:10728:1
編輯: 我發現我的錯。某些功能在瀏覽器上不起作用。
我科爾多瓦項目是通過使用「科爾多瓦創建myFolderProjectCordova創建 - 鏈接到= myFolderProjectAngular /應用程序「。在全球項目中,我有兩個文件夾,一個用於cordova(myFolderProjectCordova)和一個用於angular(myFolderProjectAngular)的文件夾。有用的文件正在編輯myForlderProjectAngular /應用程序。 – helene