Hi I am a total newbie to AngularJS. I'm trying to debug someone else's code and I'm getting an error message that I'm not sure how to fix. The error message is Uncaught ReferenceError: response is not defined. Here is my controller:
(function () {
angular
.module('vidaexpress')
.controller('accountManagerController', accountManagerController);
accountManagerController.$inject = ['$state', 'accountManagerService', 'toastr'];
function accountManagerController($state, accountManagerService, toastr) {
var vm = this;
vm.updatePassword = updatePassword;
vm.updatePhone = updatePhone;
init();
function init(){
getCustomerInfo();
}
function getCustomerInfo() {
accountManagerService.getCustomerInfo().then(function (response) {
vm.customerInfo = response;
}, function (error) {
vm.error = error;
});
}
function updatePassword(password) {
accountManagerService.updatePassword(password).then(function (response) {
if (response.error) {
displayError(response.error);
} else {
$state.go('main.manage.index');
}
}, function (error) {
displayError(response.error);
});
}
function updatePhone(phone) {
accountManagerService.updatePhone(phone).then(function (response) {
if (response.error) {
displayError(response.error);
} else {
$state.go('main.manage.index');
}
}, function (error) {
displayError(response.error);
});
}
function displayError(error) {
toastr.error(error, 'Error');
}
}
})();
and this is my service. If any other information is needed please let me know (function () {
angular
.module('vidaexpress')
.service('accountManagerService', accountManagerService);
accountManagerService.$inject = ['$http', 'apiUrl'];
function accountManagerService($http, apiUrl) {
var baseUrl = apiUrl.account;
this.updatePassword = updatePassword;
this.updatePhone = updatePhone;
this.getCustomerInfo = getCustomerInfo;
function getCustomerInfo() {
return $http.get(baseUrl + 'getCustomerInfo').then(function (response) {
return response.data;
}, function (error) {
});
}
function updatePassword(password) {
return $http.post(baseUrl + 'updatePassword', password)
.then(function (response) {
return {};
}, function(error) {
return { error: error.data.message };
});
}
function updatePhone(phone) {
return $http.post(baseUrl + 'updatePhone', phone)
.then(function (reponse) {
return {};
}, function (error) {
return { error: error.data.message };
});
}
}
})();
Here is my view:
form class="form form-vertical" id="new_pass" name="new_pass" ng-submit="new_pass.$valid && vm.updatePassword(vm.password)" novalidate>
<div class="form-group" ng-show="vm.updatePasswordError">
<span class="alert alert-danger col-lg-12">{{vm.updatePasswordError}}</span>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<label for="currpw" class="control-label">{{'PASSWORD_ENTER_CURRENT' | translate }}</label>
<input id="currpw" class="form-control" title="New Password" required="" type="password" ng-model="vm.password.oldPassword">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<label for="currpw" class="control-label">{{ 'PASSWORD_ENTER_NEW' | translate }}</label>
<input id="signuppassword" name="signuppassword" type="password" class="form-control" autocomplete="off" required ng-model="vm.password.newPassword" ng-pattern="/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,18}$/" ng-focus="vm.signuperror = '';">
<div class="error_msg" ng-show="new_pass.signuppassword.$error.required && submit">{{ 'PASSWORD_ENTER' | translate }}</div>
<div class="error_msg" ng-show="new_pass.signuppassword.$error.pattern && submit">
{{ 'PASSWORD_ERROR_PATTERN' | translate }}
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<label for="newpw" class="control-label">{{ 'PASSWORD_ENTER_NEW_CONFIRM' | translate }}</label>
<input id="confirmpassword" name="confirmpassword" type="password" class="form-control" required ng-model="vm.password.confirmpassword" ve-compare-to="vm.password.newPassword" ng-focus="vm.signuperror = '';">
<div class="error_msg" ng-show="new_pass.confirmpassword.$error.required && submit">{{ 'PASSWORD_ENTER_CONFIRM' | translate }}</div>
<div class="error_msg" ng-show="new_pass.confirmpassword.$error.veCompareTo && submit">{{ 'PASSWORD_ERROR_MATCH' | translate }}</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-4 col-lg-12 buttonblocks">
<button type="submit" class="btn btn-primary button_dkblue_lg" ng-click="submit=true;">{{ 'UPDATE' | translate }}</button>
</div>
<div class="col-lg-8 col-xs-12 buttonblocks align-right">
<a ui-sref="main.manage.index" class="btn btn-primary button_dkblue_lg">{{ 'CANCEL' | translate }}</a>
</div>
</div>
<style>
.far_right{float:right;}
.pwalert { margin-top: 29px;}