Using this
instead of $scope
works.
function AppCtrl($scope){_x000D_
$scope.searchText = "";_x000D_
$scope.check = function () {_x000D_
console.log("You typed '" + this.searchText + "'"); // used 'this' instead of $scope_x000D_
}_x000D_
}
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>_x000D_
_x000D_
<div ng-app>_x000D_
<div ng-controller="AppCtrl">_x000D_
<input ng-model="searchText"/>_x000D_
<button ng-click="check()">Write console log</button>_x000D_
</div>_x000D_
</div>
_x000D_
Edit: At the time writing this answer, I had much more complicated situation than this. After the comments, I tried to reproduce it to understand why it works, but no luck. I think somehow (don't really know why) a new child scope is generated and this
refers to that scope. But if $scope
is used, it actually refers to the parent $scope because of javascript's lexical scope feature.
Would be great if someone having this problem tests this way and inform us.