我已經定義爲指令如下:AngularJS UI自舉的DatePicker不能正常工作
模板
<div class="date-picker">
<div class="row">
<div class="col-md-6">
<label for="{{datePickerId}}">{{labelText}}</label>
<p class="input-group">
<input type="text"
id="{{datePickerId}}"
class="form-control"
datepicker-popup="{{format}}"
ng-model="dt"
is-open="opened"
datepicker-options="dateOptions"
disabled="disabled"
ng-required="true"
close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
</div>
指令
//TypeScript
module MyApp.Directives {
/** Scope for Messaging directive. */
export interface IMaDatePickerScope extends ng.IScope {
dt: Date;
today(): void;
clear(): void;
disabled(date, mode): boolean;
open($event): void;
opened: boolean;
dateOptions;
formats: string[];
format: string;
}
export class MaDatePicker implements ng.IDirective {
restrict = "E";
templateUrl = TEMPLATES + 'ma-date-picker.html';
replace = true;
transclude = true;
scope = {
labelText: '@',
datePickerId: '='
}
link = (scope: IMaDatePickerScope) => {
scope.today =() => {
scope.dt = new Date();
}
scope.today();
scope.clear =() => {
scope.dt = null;
}
scope.disabled = (date: Date, mode) => {
return (mode == 'day' && (date.getDay() === 0 || date.getDay() === 6)); //disable Saturday and Sunday
}
scope.open = ($event) => {
$event.preventDefault();
$event.stopPropagation();
scope.opened = true;
}
scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
}
scope.formats = ['yyyy-MM-dd', 'dd-MMMM-yy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
scope.format = scope.formats[0];
}
controller = ($scope: IMaDatePickerScope) => {
}
}
}
它是由the DatePicker section here採取和應該以像在該頁面上顯示的彈出版本一樣運行。但是,每當我點擊日曆按鈕啓動指令時,日曆就會以破碎的方式出現。此外,當我點擊彈出式日曆中的「下個月」箭頭時,日曆不斷向左擴展。我的代碼有問題嗎?我沒有添加任何樣式,因爲根據網站似乎沒有任何樣式,但我想在分離現有樣式之前檢查代碼是否有明顯錯誤。
你使用的是什麼版本的庫? – 2014-10-31 18:44:27
Angular v1.2.16 Angular UI Bootstrap 0.11.0 – muttley91 2014-10-31 18:55:50
您是否在ui-bootstrap之外還包含了ui-bootstrap-tpls文件? – Ken 2014-10-31 19:34:35