0

HTML:

<input ng-model='user.email' type="text" value='' />
<input ng-model='user.password' type="password" value='' />
<div ng-click='tryEnter()'>
   <span>Enter</span>
</div>

JS:

.controller('enterController', ['$scope', '$http', '$q', function($scope, $http, $q) {
        $scope.user = {};
        $scope.tryEnter = function() {
            debugger;


        }                           
    }])

Inside click function I try to get value from input by ng-model. Bot $scope not abailable inside function.

Darien Fawkes
  • 3,023
  • 7
  • 24
  • 35
  • `$scope` will be available inside `tryEnter` function. Can you replicate it otherwise. Do a `console.log($scope.user)` and see for yourself. Don't fall into [browser debugging not showing the variable as available](http://stackoverflow.com/questions/28388530/why-does-chrome-debugger-think-closed-local-variable-is-undefined). – PSL Oct 27 '15 at 19:35
  • Ok) it now work. But I wonder why it work after some time? When I write it it do not work. – Darien Fawkes Oct 27 '15 at 19:37

1 Answers1

0

You could pass the scope of the value itself as an argument to your click handler (the tryEnter) function. There's some good answers on this StackOverflow question here: How to pass scope variable through ng-click function?

Community
  • 1
  • 1
Joseph Quigley
  • 346
  • 1
  • 12