1

I am trying to combine input text with HTTP get. I tried some methods it works but it' doesn't what I want. I have some URL like this http://localhost/web.php?tN=false&f5=kaka in f5 get some data from input in HTML. This my HTML

<div class="list">
    <label class="item item-input item-floating-label">
        <span class="input-label"><i class="glyphicon glyphicon-user"></i> Username</span>
        <input id="inputPassword" class="form-control" placeholder=" Username" name="loginname" type="text" ng-model="loginData.username" ng-click="submitFunction()" required>
    </label>
    <label class="item item-input item-floating-label">
        <span class="input-label"><i class="glyphicon glyphicon-lock"></i> Password</span>
        <input id="inputPassword" class="form-control" placeholder=" Password" name="password" type="password" ng-model="loginData.password" required>
    </label>
</div>

and this my controller

$scope.submitFunction = function() {
    kaka.falselogin($scope.loginData.username).success(function(data) {
        console.log(data);
    });
};

My problem is that I must click after input in form username to get data. It's complicated if I must get data after input in form username anyone has an idea ? Please help me to solve my problem. Thanks

2
  • 1
    try ng-change. also debounce all elements which trigger a digest cycle. Commented May 29, 2017 at 7:10
  • yeah it work thank Commented May 29, 2017 at 7:16

1 Answer 1

1

You can just use the ng-change directive. It'll run the provided function whenever the input`s value changed.

<input id="inputPassword" class="form-control" placeholder=" Username" name="loginname" type="text" ng-model="loginData.username" ng-change="submitFunction()" required>

Considering you issue HTTP requests on each change, you'd basically flood the server. To solve that issue you can debounce the model so that it takes x ms until the new value will be applied.

ng-model-options='{ debounce: 1000 }'

In combination it would look like this:

<input id="inputPassword" class="form-control" placeholder=" Username" name="loginname" type="text" ng-model="loginData.username" ng-model-options='{ debounce: 1000 }' ng-change="submitFunction()" required>

There you go :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.