gpt4 book ai didi

javascript - 错误: [$injector:unpr] Unknown provider: $cordovaSmsProvider <- $cordovaSms <- smsController

转载 作者:行者123 更新时间:2023-12-03 06:45:43 24 4
gpt4 key购买 nike

我正在尝试使用 cordova-sms-plugin 和 ionic 发送短信,但收到错误。我尝试了此网站上所有可能的答案,但问题仍然没有解决。

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

谁能帮我解决这个错误吗?提前致谢。

最佳答案

你的代码看起来不错。可能导致错误:[$injector:unpr]未知提供程序:错误的唯一问题是:

  1. 您尚未加载 ngCordova 模块作为依赖项(您已经完成了)或

  2. lib/ng-cordova.min.js 脚本文件不在正确的路径中并且未下载。

确保您的控制台中不存在这两个问题,并且您的代码应该可以正常工作

关于javascript - 错误: [$injector:unpr] Unknown provider: $cordovaSmsProvider <- $cordovaSms <- smsController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37741942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com