简体   繁体   English

Angular UI Bootstrap日期选择器在打开时切换到今天

[英]Angular UI Bootstrap datepicker switching to today on open

Background 背景

I'm adding a date, with Angular UI Bootstrap support, similar like I have implemented in this Plunk . 我正在添加一个日期,该日期具有Angular UI Bootstrap支持,类似于在此Plunk中实现的日期 The Plunk does exactly what I want it to do. 朋克完全按照我的意愿去做。

However, on my local attempt, the selected date switches to today , rather than the date set in ng-model . 但是,在我的本地尝试中,选择的日期切换为today ,而不是ng-model设置的日期。

Local code 本地代码

<p class="input-group">
    <input type="text" class="form-control"
            uib-datepicker-popup="{{format}}"
            ng-model="person.DateOfBirth"
            is-open="stats.DateOfBirthOpened" />
    <span class="input-group-btn">
        <button type="button" class="btn btn-default" ng-click="openDatepicker($event)">
            <i class="fa fa-calendar"></i>
        </button>
    </span>
</p>

Script: 脚本:

$scope.format = "dd/MM/yyyy";

$scope.stats = {
    DateOfBirthOpened: false
};

$scope.openDatepicker = function ($event) {
    $scope.stats.DateOfBirthOpened = true;
};

Plunk code 随便码

<div class="input-group">
    <input type="text" class="form-control" 
            uib-datepicker-popup="{{format}}" 
            ng-model="today" 
            is-open="status.opened" 
            min-date="minDate" 
            max-date="maxDate" 
            datepicker-options="dateOptions" 
            ng-required="true" 
            close-text="Close" />
    <span class="input-group-btn">
    <button type="button" class="btn btn-default" ng-click="open($event)">
        <i class="fa fa-calendar"></i>
     </button>
    </span>
</div>

Script: 脚本:

$scope.status = {
    opened: false
};

$scope.open = function ($event) {
    $scope.status.opened = true;
};

$scope.dateFormat = "dd/mm/yyyy";

Question

As far as I can tell both implementations are very similar (identical ignoring semantical differences) , so why is the local code not working correctly (displaying today on open rather than ng-model value)? 据我所知,两种实现都非常相似(完全忽略语义差异) ,那么为什么本地代码不能正常工作(今天显示为open而不是ng-model值)?

Addendum 附录

Full controller javascript code as requested: 要求的完整控制器javascript代码:

"use strict";

angular.module("controllers.mainControllers")
    .controller("personDetailController", [
        "$scope",
        function ($scope) {
            var self = {};

            self.Get = function () {
                if (coreUtilityService.IsValid($rootScope.PersoonId)) {
                    apiService.Get("api/person/" + $rootScope.PersoonId).then(function (person) {
                        $scope.person = person;
                        $scope.title = coreUtilityService.CombineTwoValuesWithSpace(person.Firstname, person.Lastname);
                    });
                };
            }

            // === $SCOPED === //

            self.Get();

            $scope.format = "dd/MM/yyyy";

            $scope.stats = {
                DateOfBirthOpened: false
            };

            $scope.openDatepicker = function ($event) {
                $scope.stats.DateOfBirthOpened = true;
            };
        }]);

And $scope.person output: 和$ scope.person输出:

{PersonId: "9245fe4a-d402-451c-b9ed-9c1a04247482", Firstname: "Jackie", Lastname: "Chan", DateOfBirth: "1968-05-17T00:00:00", CreateDate: "2015-12-11T09:15:49.403"…}
CreateDate: "2015-12-11T09:15:49.403"
DateOfBirth: "1968-05-17T00:00:00"
Firstname: "Jackie"
Lastname: "Chan"
ModifyDate: "2015-12-11T09:15:49.403"
PersonId: "9245fe4a-d402-451c-b9ed-9c1a04247482"

The date format in your plunk is wrong use "{{dd/MM/yyyy}}" instead of "{{dd/mm/yyyy}}" . 您的插件中的日期格式错误,请使用"{{dd/MM/yyyy}}"而不是"{{dd/mm/yyyy}}"

EDIT: Also the plunk example does not bind the format correctly. 编辑:另外,松散的示例未正确绑定格式。 Change {{format}} to {{dateFormat}} . {{format}}更改为{{dateFormat}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM