我在Cordova / Ionic应用程序中使用ngCordova。构建它后,我得到以下错误消息:
未捕获的ReferenceError:未定义$ cordovaOauth
index.html
app.js
另外,如果我单击登录按钮
<div class="button button-block button-positive"ng-controller="modalController" ng-click="facebookLogin()">Facebook Login</div>
我会收到另一条错误消息。
失误
这是函数所在的位置
控制者
.controller('modalController', ['$scope', '$ionicModal', '$firebase', '$ionicHistory', '$state', '$cordovaOauth', '$localStorage', '$sessionStorage','$location', function ($scope, $ionicModal, $firebase, $ionicHistory, $state, $cordovaOauth, $localStorage, $sessionStorage, $location) {
$ionicModal.fromTemplateUrl('templates/register.html', {
scope: $scope,
animation: 'slide-in-up',
backdropClickToClose: false,
hardwareBackButtonClose: false,
focusFirstInput: true
}).then(function (modal) {
$scope.modal = modal;
});
$scope.$on('$ionicView.beforeEnter', function (event, viewData) {
viewData.enableBack = true;
console.log(viewData.enableBack);
});
$scope.goBack = function () {
$ionicHistory.goBack();
console.log("back pressed");
};
/*Notice that after a successful login, the access token is saved and we are redirected to our profile. The access token will be used in every future API request for the application.*/
$scope.facebookLogin = function () {
$cordovaOauth.facebook("1234", ["email", "read_stream", "user_website", "user_location", "user_relationships"]).then(function (result) {
$localStorage.accessToken = result.access_token;
$location.path("/profile");
}, function (error) {
alert("There was a problem signing in! See the console for logs");
console.log(error);
});
};
我不明白此错误,所有文件均已放置到位,并且进行了所有注射。我在这里想念什么?
最佳答案
经过几天的研究,该解决方案得以迅速形成。
注入$ cordovaOauth
注入$cordovaOauth
是正确的。如果您分析.run
函数的主体,则会发现一个$ionicPlatform
函数调用,该调用被注入到.run
中。因此,注入$cordovaOauth
+1是合理的。
在模块中添加ngCordova
正式文档确实让我感到烦恼,他们要么在进行更改后就没有正确地更新文档,要么在细节上变得草率。我必须在ngCordova
中添加app.module
。
这解决了这个问题,但又产生了一个问题。
希望这可以帮助