Search code examples
ionic-frameworkngcordovahybrid

Simple Error - Checked other posts - ngCordova not defined


I am facing this error of

[$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module ngCordova due to:

Now I know this is related to index html not able to reference ngcordova service somehow.

index.html

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-messages.js"></script>
<script src="lib/ionic-material/dist/ionic.material.min.js"></script>
<script src="lib/chart.js/dist/Chart.min.js"></script>

<!-- cordova script (this will be a 404 during development) -->


<script type="lib/ngCordova/dist/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<script type="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>

Now, "lib/ngCordova/dist/ng-cordova.min.js" is already present. I am very sure it is a simple mistake. But still trying to figure out same.

app.js

var app = angular.module('starter', ['ionic', 'ionic-material','ngMessages', 'ngCordova']);

Solution

  • EDIT: type -> src

    Instead of

    <script type="lib/ngCordova/dist/ng-cordova.js"></script>
    <script type="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></scrip‌​t> 
    

    use

    <script src="lib/ngCordova/dist/ng-cordova.js"></script>
    <script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></script‌​>
    


    Inject ngCordova as an Angular dependency in app.js

    angular.module('myApp', ['ngCordova'])