2015-11-27 55 views
0

我有一个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


编辑: 我发现我的错。某些功能在浏览器上不起作用。

回答

0

您可能在gruntfile中有一些任务,即在index.html中注入脚本,这就是为什么导入的更改。

0

您的项目没有config.xml,它是cordova项目的基础。 请看这里: [Error: Current working directory is not a Cordova-based project.]

要启动科尔多瓦项目,你应该使用命令

cordova create PROJECTNAME 

然后你就可以在你的项目中的文件复制到WWW文件夹

+0

我科尔多瓦项目是通过使用“科尔多瓦创建myFolderProjectCordova创建 - 链接到= myFolderProjectAngular /应用程序“。在全球项目中,我有两个文件夹,一个用于cordova(myFolderProjectCordova)和一个用于angular(myFolderProjectAngular)的文件夹。有用的文件正在编辑myForlderProjectAngular /应用程序。 – helene

相关问题