$scope.myArrayOfObjects.push is not a function
I'm working with AngularJS and Angular Material. I try push a object to an array, but it sends me a message "$scope.myArrayOfObject.push is not a function".
My code:
controller("ClientesCTRL",function($scope,$http,$q,$timeout,$location, datosFactory, userFactory, $mdDialog){
$scope.clientes = [];
user = userFactory.getUser();
if(user){
$scope.selected = [];
$scope.query = {
filter : '',
order: 'rut',
limit: 5,
page: 1
};
var data = {'op':1, 'rut' : user.rut};
$http.post('functions/ClientesCTRL.php', data)
.success(function(results){
console.log(results);
$scope.clientes = results;
});
$scope.onpagechange = function(page, limit) {
var deferred = $q.defer();
$timeout(function () {
deferred.resolve();
}, 2000);
return deferred.promise;
};
$scope.onorderchange = function(order) {
var deferred = $q.defer();
$timeout(function () {
deferred.resolve();
}, 2000);
return deferred.promise;
};
$scope.verContacto = function(){
datosFactory.setClienteContacto($scope.selected[0]);
$location.path("/contactos")
};
$scope.eliminarCliente = function(ev) {
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title('Eliminar Clientes')
.content('Estás seguro?')
.ariaLabel('Lucky day')
.targetEvent(ev)
.ok('Eliminar')
.cancel('Cancelar');
$mdDialog.show(confirm).then(function() {
alert("Cliente eliminado");
}, function() {
});
};
$scope.addCliente = function(ev){
$mdDialog.show({
controller: AddClienteController,
templateUrl: 'addClienteForm.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose:true
})
.then(function(c) {
console.log(c);
var data = {'op':3, 'cl' : c, 'user':user};
console.log(data);
$scope.clientes.push(c);
$http.post('functions/ClientesCTRL.php', data)
.success(function(results){
if(results){
alert("Cliente agregado");
$scope.clientes = [];
$scope.clientes.push(c);
}else{
alert("Error al agregar cliente");
}
console.log(results);
});
}, function() {
$scope.status = 'You cancelled the dialog.';
});
};
function AddClienteController($scope, $mdDialog, $http) {
$http.post("functions/UsuarioCTRL.php",{'op':14})
.success(function(results){
if(results !== null){
$scope.formaspago = results;
}
});
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.btnAddCliente = function() {
$mdDialog.hide($scope.addCliente);
};
};
}