I use ngCordova in my Cordova/Ionic app. I get this error message after building it:
Uncaught ReferenceError: $cordovaOauth is not defined
Additionally, if I click the login button
<div class="button button-block button-positive"ng-controller="modalController" ng-click="facebookLogin()">Facebook Login</div>
I'll get another error message.
This is where the function is located
.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);
});
};
I don't understand this error, all files are in place and I made all the injections. What am I missing here?
After a couple of days researching the solution was quickly made.
Injecting $cordovaOauth
was correct. If you analyze the body of the .run
function you'll find a $ionicPlatform
function call, which was injected to .run
. So it is only logical to inject $cordovaOauth
, +1 for that.
This is something that really annoys me with offical docs, they either don't update their docs properly as soon as a change was made or they become sloppy when it comes to the details. I had to add ngCordova
in app.module
.
This solved this issue but created another one.
Hope this helps