我加入一個日期,具有角UI引導支持,就像我在類似這種Plunk已經實現。普朗克完全正是我想要它做的。
但是,在本地嘗試中,所選日期切換爲today
,而不是在ng-model
中設置的日期。
本地代碼
<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>
腳本:
$scope.format = "dd/MM/yyyy";
$scope.stats = {
DateOfBirthOpened: false
};
$scope.openDatepicker = function ($event) {
$scope.stats.DateOfBirthOpened = true;
};
普拉克代碼
<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>
腳本:
$scope.status = {
opened: false
};
$scope.open = function ($event) {
$scope.status.opened = true;
};
$scope.dateFormat = "dd/mm/yyyy";
問題
據我可以告訴這兩個實現是非常相似(相同忽略語義差異),那麼,爲什麼不能正常使用本地代碼正確(開放的今天顯示,而不是NG-模型值)?根據要求
附錄
完全控制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;
};
}]);
而且$ 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"
可以請你分享完整的JavaScript文件代碼 –
完成後,雖然我認爲不會增加太多。 – Spikee
我想你還沒有定義你想在前面展示的模型的價值。 –