【问题标题】:Display date from database in Angularjs and view the current date for update在 Angularjs 中显示数据库中的日期并查看当前日期以进行更新
【发布时间】:2017-06-29 00:40:45
【问题描述】:

我正在更新 angularjs 中的表单,其中一个字段是 Date Joined

我想显示从数据库连接到字段的日期的当前值,但是当我使用输入类型 date 时,该值不显示

但是当我将类型更改为text 时,会显示该值。

我的问题是,如何使用type=date 显示和更新date_joined

编辑: 代码如下:

HTML:

 <label class="item item-input item-stacked-label">
            <span class="input-label">
                <b>Date Joined:</b>
            </span>
            <input type="text" ng-model="memUpdate.date_joined" ng-value="memDataViaId.date_joined"></input>
        </label>

我正在使用 SQLite。

这是我在 JS 中的查询:

var query = "SELECT members.*, branches.name as branch_name, branches.id as branches, branches.name as branch_name, "
    + "groups.name as group_name, groups.id as groups, civil_statuses.name as civil_status_name, "
    + "civil_statuses.id as civil_statuses, religions.id as religions, educations.id as educations, "
    + "mem_join_resigns.date_joined as date_joined, .....

【问题讨论】:

  • 关于这个问题的信息很少。我们不知道您是否使用mySQL - 使用日期选择器? - 什么后端?对于 php,您必须格式化您的日期以对齐正确的 mysql 日期格式(请参阅stackoverflow.com/questions/22376415/…
  • 请提供您的代码,以便我们进行调查。

标签: javascript angularjs database date


【解决方案1】:
  • 您需要以“yyyy-MM-dd”格式提供日期。
  • 在控制器中注入$filter服务然后这样使用

    $filter("date")(myDate, 'yyyy-MM-dd');
    

这里,myDate 的语法是来自数据库的日期。

工作演示:

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

function MyCtrl($scope, $filter) { 
    var myDate = '2010-10-29T00:00:00';
    $scope.date = $filter("date")(myDate, 'yyyy-MM-dd');
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
    <div ng-controller="MyCtrl">
        <input type="date" ng-model="date">
    </div>
</body>

【讨论】:

    猜你喜欢
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 2019-06-02
    • 1970-01-01
    相关资源
    最近更新 更多