2016-06-10 48 views
0

我想发送短信使用科尔多瓦短信插件与离子,但我得到一个error.I尝试所有可能的答案从这个网站,但仍然是一个问题没有解决。

的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 

}]); 

这是我的模块

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(); 
    } 
    }); 
}) 

任何人都可以请帮我,我应该怎么解决这个问题? 在此先感谢。

+0

这是一个普通的角度误差,当你忘记了一步,而安装ngCordova。请按照http://ngcordova.com/docs/install/。 – yogesh

+0

显示你的模块,可以帮助你 –

+0

好吧,我已经添加模块到我的问题 – Shweta

回答

1

你的代码看起来不错。这可能会导致Error: [$injector:unpr] Unknown provider:错误唯一的问题是:

  1. 要么你没装ngCordova模块的依赖性,(你已经完成)或

  2. lib/ng-cordova.min.js脚本文件是不是在正确的道路并没有得到下载。

确保这2个问题是不是有你的控制台和您的代码应工作

+0

它完成了.Thanku – Shweta

+0

什么是确切的错误?我想这是文件路径不正确 –

+0

yes.ng-cordova.min.js在另一个文件夹中,所以它给出了一个错误。 – Shweta

相关问题