无法使用ng-model和ng-click

时间:2015-10-30 10:25:05

标签: javascript angularjs datepicker

我只是想创建一个小型的网络应用程序,用户可以在一定的时间范围内从数据库中下载值。我的html代码是这样的:

<div class="container">
            <div class='col-md-5'>
                Start Date:
                <div class="form-group">
                    <div class='input-group date' id='datetimepicker6'>
                        <input type='text' ng-model="queryDate.start" class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>
            <div class='col-md-5'>
                End Date:
                <div class="form-group">
                    <div class='input-group date' id='datetimepicker7'>
                        <input type='text' ng-model="queryDate.end" class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>


            <div class='col-md-5'>
                Service Name:
             <select id="serviceName" style="font-size: 15px;padding: 5px;width: 300px" >
                 <option></option>
                 <option ng-repeat="webService in webServices">{{ webService.fields.service }}</option>
             </select>
            </div>

            <div class='col-md-6'>
                <button type="button" id="download" ng-click="download(queryDate)" class="btn btn-theme" style="float: right">Download</button>
            </div>
        </div>

我正在尝试将开始日期和结束日期收集到ng-model

ng-model="queryDate.start"

ng-model="queryDate.end"

虽然我们可以在http://docs.angularjs.org/guide/forms中看到它非常容易从ng-model收集数据。

我的mainApp.js如下

var mainApp = angular.module("mainApp",[]);
mainApp.controller("serviceController",function($scope,$http){
$http.get("/fetchData/").success(function(response){
    $scope.webServices = response;
});
//--------- I get alert "Hola" but the next alert says "undefined" ---------
$scope.download = function(queryDate){
    alert('Hola');
    alert(queryDate);
  };
});

我希望收集两个日期字段,然后在DB中使用它们来获取数据。

1 个答案:

答案 0 :(得分:0)

<div class='input-group date' >
                        <input type='text' ng-model="queryDate.start" id='datetimepicker6'class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>

在你的JS文件中这样做 $(&#39;#datetimepicker6&#39;)日期选择器();

您必须为datepicker()

使用jquery-ui库

例如,请参阅此https://jqueryui.com/datepicker/