Shweta Shweta - 4 months ago 15x
Javascript Question

Error: [$injector:unpr] Unknown provider: $cordovaSmsProvider <- $cordovaSms <- smsController

I am trying to send SMS using cordova-sms-plugin with ionic but I am getting an error.I tried all the possible answers from this site but still an issue has not resolved.


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

<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/" 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>

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

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

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

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


.controller('smsController',["$scope", "$cordovaSms",function($scope,$cordovaSms){

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


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


This is my module

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)

// 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.
if(window.StatusBar) {

Can anyone please help me how should I resolve this error?
Thanks in advance.


Your code looks fine. The only problem which could cause the Error: [$injector:unpr] Unknown provider: error are:

  1. Either you have not loaded ngCordova module as dependency, (which you already have done) or

  2. lib/ng-cordova.min.js script file is not in the right path and not getting downloaded.

Ensure that these 2 issues are not there in your console and your code should work