Im currently using Ionic framework (inc AngularJS) with PhoneGap to develop a mobile application. When running in chrome the application works seamlessly (I have been debugging the errors while in development).
I deployed to the iOS simulator today and hooked it upto safari developer tools and got the follow error.
Error: Can't find variable: $
My controllers etc work fine here however my postLogin()
function does not.
Here is a cutdown version of my LoginController, Am i not passing $ correctly?
.controller('LoginCtrl', function($http, $ionicLoading, $scope, $state) {
$scope.login = {};
$scope.handlerLogin = function(response){
$ionicLoading.hide();
if(response.data.response == 1){
localStorage.setItem("token",response.data.token);
$state.go("app.search", {}, {reload: true});
}else if(response.data.response == 0){
$scope.login.password = '';
$('#errorMessageText').text('Login failed. Please try again.');
$('#errorMessage').fadeIn(2000, function(){$('#errorMessage').fadeOut('slow');});
}else{
//handle general error?
}
}
$scope.postLogin = function() {
$ionicLoading.show({
template: 'loading'
});
var formdata = $scope.login;
var url = api + 'api/login';
$.ajax({
type: "GET",
url: url,
data: formdata,
success: function success(data){
$scope.handlerLogin(data);
},
dataType: 'jsonp'
});
};
$scope.doLogin = function() {
if($scope.login.email == null || $scope.login.password == null){
$('#errorMessageText').text('Please complete both fields.');
$('#errorMessage').fadeIn(2000, function(){$('#errorMessage').fadeOut('slow');});
}
else{
$scope.postLogin();
}
}
});
Please ignore than im using JSONP
for logging in for now.
Any pointers would be a great help! Scratching my head for hours now!!