How can I preform a GET request when user input equals current time?

GlobalJim

I am using angular.js for my GET request.

var app = angular.module('app', []);

app.controller('ArduinoCtrl', function ($scope, $http) {
    $scope.response = {};
    $scope.progress = false;
    $scope.setServo = function (setting) {
        $scope.progress = true;
        var url = "http://192.168.2.4/arduino/" + setting
        $http.get(url).then(sucess, error).then(function () {
            $scope.progress = false;
        });

    }


});

I would like to call the setServo(setting) GET request when a time (two ints), in hours and minutes that is set by the user, matches the current time. The user inputted time is set with two range input types.

HTML code:

<div class="jumbotron">
            <h2>Enter the time for daily dispense</h2>
            <input type="number" min="1" max="3" id="num"/>
            <div>
                <p>Hour: </p>
                <input type="range" min="1" max="24" name="hour" id="hour" onchange="updatedHourInput(this.value)" />

            </div>
            <div>
                <p>Minutes: </p>
                <input type="range" min="00" max="55" step="5" name="minute" id="minute" onchange="updateTextInput(this.value)" />
            </div>
            <div>
                <span>Entered Time=  </span><span id="textHour"></span><span>:</span><span id="textMinute"></span>
                <br />
                <span>Current Time= </span><span id="time"></span>
            </div>
        </div>

My JavaScript code, this is called onload in the .

 function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
    var userHour = parseInt(document.getElementById('hour').innerHTML);
    var userMinute = parseInt(document.getElementById('minute').innerHTML);
    var num = parseInt(document.getElementById('num').value);
    var t = setTimeout(function(){startTime()},500);
    if ((h == userHour) && (m = userMinute)) {
        setServo(num);


    }
}
Matías Fidemraizer

First of all, I can't understand why you're not binding inputs using regular ng-model approach:

<!-- Example: -->
<input type="text" ng-model="hour" />

Once you've bound an input to some scope's property using ng-model, the so-called input and property will react to changes of both (this is two-way binding).

In the other hand, you'll implement a hour and minute properties in your controller's $scope, and you won't access the DOM to get inputs' values, since Angular data-binding will set input values into these properties and viceversa when you set the properties.

If you go this way, you can $watch property changes and once hours and minutes are current time, you can trigger a function:

module.controller("X", ["$scope", function($scope) {
    $scope.hours = 0;
    $scope.minutes = 0;

    var onTimeChange = function() {
        // Eval $scope.hours and $scope.minutes
        // and trigger whatever function you want!
    }; 

    $scope.$watch("hours", onTimeChange);
    $scope.$watch("minutes", onTimeChange);
});

Let me give you an advise: AngularJS is about data-binding, separation of concerns and controllers, models or services shouldn't access the DOM directly - this is why data-binding exists -. Directives are the entity whithin Angular world that may access or modify the DOM using regular DOM or jQuery (or any other DOM manipulation library).

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can i get request in Filter

분류에서Dev

How can I run an SSRS report as the current Windows User?

분류에서Dev

Zenity question - how can I use user input?

분류에서Dev

How can I change uipanel dimensions by using user input?

분류에서Dev

How do I get user input (int) to sum

분류에서Dev

How can I pause a loop until I get a users input?

분류에서Dev

How can I get javascript to write dates in my input boxes?

분류에서Dev

How can I get total user in a group from database by PHP

분류에서Dev

How can I get time efficent by creating an array with for loop?

분류에서Dev

How can i get my query execution time in logging

분류에서Dev

How can I get the contents of a file one line at a time?

분류에서Dev

How do i get this kind of time format when "now" in javascript?

분류에서Dev

how to get the current date and time of the system in java

분류에서Dev

How Can I tell if the current user is Admin from Windows Command Line

분류에서Dev

I need to get from the user input random

분류에서Dev

How can i manage this request?

분류에서Dev

How can i restrict user from not selecting other file types using input type file with react and typescript?

분류에서Dev

How can I print out the delimiter character and allow user to edit line while reading standard input?

분류에서Dev

How can I match a user id value from a form input to records in my database?

분류에서Dev

How can i get cakephp current model's foreign key column name?

분류에서Dev

How i can get the td data getting from css to attach to my current row ,and use for my logic

분류에서Dev

How can I get paths relative to the current directory from git status?

분류에서Dev

How can i get last week, current week and last month record from mysql

분류에서Dev

When writing a bash script, how do I get the absolute path of the location of the current file?

분류에서Dev

How can i insert current date in robomongo?

분류에서Dev

Is there anyway I can get the time of cached file?

분류에서Dev

(discord.py) How can I get a list of how many permissions a user has

분류에서Dev

Android how i can do GET request to my server every minute?

분류에서Dev

How can I trace out entire GET request from jersey api client call

Related 관련 기사

  1. 1

    How can i get request in Filter

  2. 2

    How can I run an SSRS report as the current Windows User?

  3. 3

    Zenity question - how can I use user input?

  4. 4

    How can I change uipanel dimensions by using user input?

  5. 5

    How do I get user input (int) to sum

  6. 6

    How can I pause a loop until I get a users input?

  7. 7

    How can I get javascript to write dates in my input boxes?

  8. 8

    How can I get total user in a group from database by PHP

  9. 9

    How can I get time efficent by creating an array with for loop?

  10. 10

    How can i get my query execution time in logging

  11. 11

    How can I get the contents of a file one line at a time?

  12. 12

    How do i get this kind of time format when "now" in javascript?

  13. 13

    how to get the current date and time of the system in java

  14. 14

    How Can I tell if the current user is Admin from Windows Command Line

  15. 15

    I need to get from the user input random

  16. 16

    How can i manage this request?

  17. 17

    How can i restrict user from not selecting other file types using input type file with react and typescript?

  18. 18

    How can I print out the delimiter character and allow user to edit line while reading standard input?

  19. 19

    How can I match a user id value from a form input to records in my database?

  20. 20

    How can i get cakephp current model's foreign key column name?

  21. 21

    How i can get the td data getting from css to attach to my current row ,and use for my logic

  22. 22

    How can I get paths relative to the current directory from git status?

  23. 23

    How can i get last week, current week and last month record from mysql

  24. 24

    When writing a bash script, how do I get the absolute path of the location of the current file?

  25. 25

    How can i insert current date in robomongo?

  26. 26

    Is there anyway I can get the time of cached file?

  27. 27

    (discord.py) How can I get a list of how many permissions a user has

  28. 28

    Android how i can do GET request to my server every minute?

  29. 29

    How can I trace out entire GET request from jersey api client call

뜨겁다태그

보관