I need to update phone number to the controller when it is taken from a dial pad. When dial pad exceed 9 digits console log showing the number but it is not updated in Controller.Inside the controller function I added alert. So alert showing undefined variable.
Controller
var app = angular.module('myApp', []);
app.controller('PosController', function ($scope, $http) {
$scope.phonenumber="";
var url = window.location.protocol + "://" + window.location.host + "/" + window.location.pathname;
$scope.updatePhone = function (id) {
$scope.phonenumber=id;
alert('Here the number should be, but is not: '+ id + "---:" + $scope.phonenumber);
$scope.phonenumber="";
};
});
View
<div ng-app="myApp" ng-controller="PosController" class="panel" >
<div class="input-group col-xs-4">
<div class="input-group-btn">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal">Telefono</button>
</div><!-- /btn-group -->
<div ng-app="myApp" ng-controller="PosController">
<input id="phonenumber" class="form-control" ng-model="phonenumber" />
<!--<input type="text" id="phonenumber" ng-model="myModel" ng-keyup="(myModel.length >= 3) && myFunction()" class="form-control" data-inputmask='"mask": "(999) 999-9999"' data-mask>-->
</div>
<div class="input-group-btn" >
<button type="button" class="btn btn-success">Cliente</button>
</div><!-- /btn-group -->
<div ng-app="myApp" ng-controller="PosController">
<input type="text" id="cliente" onclick="valor();" class="form-control" ng-focus="updatePhone($('#phonenumber').val());">
</div>
</div>
</div>
Function
function updatePhoneNumber(btnpressed){
$("#phonenumber").val($("#phonenumber").val() + btnpressed);
if ($("#phonenumber").val().length >9){
console.log('validando '+ $("#phonenumber").val());
$('#cliente').focus();
$('#myModal').modal('hide');
}
}
ng-clickinstead of standard DOM events and also use Angular compatible modals. Also if you are going to be changing urls, you'd want to use $location service and get/set location via method like$location.path()