$Scope upgrade problem with Cordova and Angularjs

Asked

Viewed 99 times

0

Hello. I am developing an app using Cordova, Ionic and Angularjs. And I have a problem updating an input.

I have the following function that runs on an ng-click:

$scope.buscarContato = function(){
$scope.phone = [];
$scope.phoneId = 0;
$scope.contact = [];
navigator.contacts.pickContact(function (contact){
  $scope.$apply(function(){
    $scope.contact = contact;
  });
  $scope.selecionarPhone(contact.phoneNumbers); 
},function (err){
   console.log('Error: ' + err);
});
};


$scope.selecionarPhone = function(phoneNumbers){
var phones = [];
var phoneId = [];
if(!phoneNumbers) return;
 for(var i = 0; i < phoneNumbers.length; i++){
  phones.push({"text": phoneNumbers[i].value});
  phoneId.push( phoneNumbers[i].id );
}

var options = {
  titleText: "Escolha o número a ser pesquisado",
  buttons: phones,
  cancelText: 'Cancelar',
  cancelOnStateChange: true,
  buttonClicked: function (index) {
    $scope.phone = phones[index].text;
    $scope.phoneId = phoneId[index];
    $scope.contatoExiste = true;
    return true;
  }
};

$ionicActionSheet.show(options);

};

At the end of the execution, I change the value of an input on the screen, in the

$scope.phone = removerMascara(phones[index].text);

Input:

<input type="tel" placeholder="11999999999" name="phone" data-ng-model="phone" maxlength="15" required>

The search and change of the input happens normally, but if I change the input manually, I can no longer change it with the data of the agenda, and even the first line of the function, where zero data, works.

How I should manipulate this scope correctly?

Edit: The problem was solved by placing the phone scope under a Parent: $Scope.data.phone

Can anyone explain why there was this difference?

  • Worse guy who is very bugged Angularjs with Córdoba. I’m going through some difficulties too. Just so you know you are not alone in this :)

  • Yeah. I ran some tests here, leaving the button solely to reset the input, and he didn’t even do that.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.