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 a 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 run, I change the value of an input on the screen,
$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 schedule data, and even the first line of the function, where zero the data, works.
How should I handle 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 such a difference?