在我上次升级后,我尝试启动我的应用,在应用中使用时出现了很多错误。
这是我更新项目后的错误之一(在登录时,我在几个不同的函数中有许多未定义的):
Error: updateUserDetails is not defined
$scope.register/<@http://localhost:8100/js/controls/loginCntrls.js:126:21
processQueue@http://localhost:8100/lib/ionic/js/ionic.bundle.js:27879:28
scheduleProcessQueue/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:27895:27
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29158:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:28969:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:13
done@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23676:36
completeRequest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23848:7
requestLoaded@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23789:9
此外,当我尝试使用Facebook登录时:
ionic.bundle.js:26794 ReferenceError: facebookConnectPlugin is not defined
at Object.login (ng-cordova.js:2190)
at Object.login (facebookService.js:35)
at Scope.$scope.fbLogin (loginCntrls.js:34)
at fn (eval at compile (ionic.bundle.js:27638), <anonymous>:4:290)
at ionic.bundle.js:65427
at Scope.$eval (ionic.bundle.js:30395)
at Scope.$apply (ionic.bundle.js:30495)
at HTMLButtonElement.<anonymous> (ionic.bundle.js:65426)
at defaultHandlerWrapper (ionic.bundle.js:16787)
at HTMLButtonElement.eventHandler (ionic.bundle.js:16775)
以下是updateUserDetails
页面:
angular.module('starter.controllers',[])
.controller('loginCtrl', function($scope, $rootScope, $state, $fbHelper, $ionicLoading, $uiHelper, $api, $ionicHistory, $parsePush) {
$scope.user = {
email: "",
password: ""
};
function handleInputError(emailVal, passwordVal){
var errorMsg = '';
if(!emailVal){
errorMsg = 'Please insert a valid email address';
} else if(!passwordVal) {
errorMsg = 'Please insert your password';
}
if(errorMsg) {
$uiHelper.popError("", errorMsg, function(){});
}
}
function goToFeed(){
$state.go('app.feeds.latest', {type: "getLatestQuestions", reload: true});
}
...
})
.controller('registerCtrl', function ($scope, $rootScope, $state, $ionicLoading, $uiHelper, $api, $ionicHistory, $parsePush) {
console.log("init registerCtrl");
$scope.user = {
email: "",
nickname: "",
password: "",
verify: "",
gender: "m"
};
$scope.register = function($event){
$event.target.blur();
var emailVal = $scope.user.email,
nicknameVal = $scope.user.nickname,
passwordVal = $scope.user.password,
verifyVal = $scope.user.verify,
genderVal = $scope.user.gender;
if(!emailVal || !passwordVal || !nicknameVal || !verifyVal || !genderVal || passwordVal!= verifyVal ){
handleInputError(passwordVal, verifyVal);
return;
}
$ionicLoading.show();
$api.register(emailVal, nicknameVal, passwordVal, genderVal).then(function(data){
if(data && data.error){
$uiHelper.popError("", data.error, function(){});
} else if(data && data._id){
updateUserDetails(data.user); //ERROR IS HERE
$ionicHistory.nextViewOptions({disableBack: true});
$parsePush.initParseNotifications();
}
});
}
});
答案 0 :(得分:0)
试试这个:
var updateUserDetails = function(data){
$rootScope.$broadcast('user:updated',{
userId : data._id,
userPicture: data.picture,
userName: data.name,
gender: data.gender
});
}
updateUserDetails(data.user);
答案 1 :(得分:0)
您似乎正在调用此行
updateUserDetails(data.user); //Error in this line
寄存器中的。该函数看起来像是在loginCtrl函数中定义的(我无法确定,因为您从示例中省略了相当多的代码)。如果这是您尝试从多个控制器调用的函数,则应该考虑在服务中定义它并将该服务注入需要它的控制器中。
像这样:
.factory('User', function($rootScope){
return {
updateUserDetails: function(data){
$rootScope.$broadcast('user:updated',{userId : data._id, userPicture: data.picture, userName: data.name, gender: data.gender});
}
}
您需要确保在服务中有对用户的引用,但希望这可以帮助您入门。