I'm trying to read a $scope variable value inside my angular controller function, but I got the undefined, when I tried to print it in the console, which is pretty strange since I can successfully set its value inside the controller and show it correctly in my html, here is the controller part I tried to read this value:
$scope.findUserByTelephone = function() {
console.log($scope.telephone);
}
my html:
<label for="telephone">telephone:</label>
<input type="number" id="telephone" ng-model="telephone"/>
<button ng-click="findUserBytelephone()" >search</button>
When I click the button, I got undefined print out. But if I set $scope.telephone value inside the controller before the findUserByTelephone() function :
$scope.telephone = 1211;
This value can be print out, and it can be showed in my html input area. But if I change this value in the input area, it still print out the original value I set in the controller. In this case, still 1211. Another thing is if I put
{{telephone}}
in my html, this area does change with my input, but the value print out inside the controller is still the old value. Is there anyone can tell me where goes wrong and how can I fix this? Thx in advance.
For those who want to check the entire project, here is the link: https://github.com/pousT/Voluncare
I am new to angular and is still learning during the development, thanks for all helps!