2016-06-10 5 views
0

Ich versuche, SMS mit Cordova-SMS-Plugin mit Ionic zu senden, aber ich bekomme einen Fehler.Ich versuchte alle möglichen Antworten Von dieser Seite hat sich jedoch immer noch kein Problem gelöst.

index.html

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 
    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 

    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="lib/ng-cordova.min.js"></script> 
    <script src="cordova.js"></script> 

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

    </head> 
    <body ng-app="starter"> 
    <ion-pane ng-controller="smsController"> 
    <ion-header-bar class="bar-stable"> 
     <h1 class="title">Ionic Blank Starter</h1> 
    </ion-header-bar> 

    <ion-content> 
     <ion-list> 
     <label class="item item-input"> 
      <span class="input-label" style="padding-top: 50px" >Number</span> 
      <input type="number" ng-model="sms.number"> 
     </label> 

     <label class="item item-input"> 
      <span class="input-label">Message</span> 
      <input type="text" ng-model="sms.message"> 
     </label> 

     <button class="button button-full button-positive" ng-click="sendSms()"> 
      Send 
     </button> 
     </ion-list> 
    </ion-content> 
    </ion-pane> 
    <!--<ion-pane>--> 
     <!--<ion-header-bar class="bar-stable">--> 
     <!--<h1 class="title">Ionic Blank Starter</h1>--> 
     <!--</ion-header-bar>--> 
     <!--<ion-content>--> 
     <!--</ion-content>--> 
    <!--</ion-pane>--> 
    </body> 
</html> 

aap.js

.controller('smsController',["$scope", "$cordovaSms",function($scope,$cordovaSms){ 
    $scope.sms={}; 

    var options = { 
     replaceLineBreaks: false, // true to replace \n by a new line, false by default 
     android: { 
      intent: 'INTENT' // send SMS with the default SMS app 
      //intent: ''  // send SMS without open any other app 
     } 
    } 

     $scope.sendSms=function(){ 
     console.log($scope.sms.number); 
     console.log($scope.sms.message); 

     $cordovaSms 
      .send($scope.sms.number, $scope.sms.message, options) 
      .then(function() { 
       // Success! SMS was sent 
       console.log('Success'); 
      }, function(error) { 
       // An error occurred 
       console.log(error); 
      });//then 
    }//sendSms 

}]); 

Das ist mein Modul ist

var app = angular.module('starter', ['ionic','ngCordova']) 
.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 

     // Don't remove this line unless you know what you are doing. It stops the viewport 
     // from snapping when text inputs are focused. Ionic handles this internally for 
     // a much nicer keyboard experience. 
     cordova.plugins.Keyboard.disableScroll(true); 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 

Kann mir jemand bitte helfen, wie soll ich diesen Fehler beheben? Vielen Dank im Voraus.

+0

Es ist ein regelmäßiger Winkelfehler arbeiten, wenn Sie einen Schritt vergessen haben, während ngCordova installieren. Bitte folgen Sie http://ngcordova.com/docs/install/. – yogesh

+0

zeigen Sie Ihr Modul, das Ihnen helfen kann –

+0

Ok Ich habe Modul zu meiner Frage hinzugefügt – Shweta

Antwort

1

Ihr Code sieht gut aus. Das einzige Problem, das die Error: [$injector:unpr] Unknown provider: Fehler verursachen kann, ist:

  1. Entweder man nicht ngCordova Modul als Abhängigkeit geladen hat, (die Sie bereits getan haben) oder

  2. lib/ng-cordova.min.js Skriptdatei ist nicht in dem richtigen Weg und nicht heruntergeladen werden. Stellen Sie sicher,

, dass diese zwei Fragen, die nicht dort in der Konsole sind und der Code sollte

+0

Es ist fertig.Thanku – Shweta

+0

Was war der genaue Fehler? Ich denke, es war der Dateipfad nicht korrekt –

+0

yes.ng-cordova.min.js war in einem anderen Ordner.so gab es einen Fehler. – Shweta