I'm using Angular Straph Modal
to change user's password, I defined 2 empty variables, and when user clicks on the button change it call a function and send parameters to our API, but for some reason it's not working, if I place the same inputs with the same variables and functions outside the modal it does data binding without problems, I've checked the Modal $scope
and it works but for some reason I can't get data filled by the user and I'm always getting null
instead of users value.
Here's my HTML.
<div class="u-Basic-Modal--body">
<div class="form-group">
<label>Contraseña Actual:</label>
<input type="password" class="form-control" ng-model="oldPassword"/>
{{ oldPassword }}
</div>
<div class="form-group">
<label>Nueva Contraseña:</label>
<input type="password" class="form-control" ng-model="newPassword"/>
{{ newPassword }}
</div>
</div>
<div class="u-Basic-Modal--footer text-right">
<button class="u-Basic-Modal--button cancel" ng-click="$hide()">Cancelar</button>
<button class="u-Basic-Modal--button success" ng-click="changePassword()">Aplicar</button>
</div>
My controller.
app.controller('usersProfileCtrl', ['$scope', 'apiService', '$rootScope', 'userResolution', 'statusBarService',
'$modal', function($scope, apiService, $rootScope, userResolution, statusBarService, $modal) {
$scope.user = $rootScope.userData;
$scope.newPassword = null;
$scope.oldPassword = null;
userResolution().then(function() {
if ($scope.user.firstName === null) {
$scope.user.firstName = '';
} if ($scope.user.lastName === null) {
$scope.user.lastName = '';
}
});
$scope.saveData = function() {
apiService.saveUser($scope.user).success(function() {
apiService.getUser($scope.user.id).success(function(response) {
statusBarService.showNote('LABEL_DONE', true);
$scope.user = response.data;
});
});
};
var importsModal = $modal({
scope: $scope,
template: 'components/administration/users/changepassword-tpl.html',
show: false
});
$scope.setPassword = function() {
importsModal.$promise.then(importsModal.show);
};
$scope.changePassword = function() {
apiService.changeUserPassword($scope.user, $scope.newPassword, $scope.oldPassword)
.success(function() {
importsModal.hide();
});
};
}]);
Hope you guys can help me. Regards!