【发布时间】:2014-07-18 17:16:18
【问题描述】:
我有以下代码...
<div ng-controller="CalendarCtrl">
<input type="text" ng-model="model.selectedDate" ng-change="onCalendarChange()" id="calendar" />
</div>
<script>
var app = angular.module("myApp", []);
app.controller("CalendarCtrl", function($scope) {
var currentDate = new Date();
$scope.model = { selectedDate: (currentDate.getMonth() + 1) + "/" + currentDate.getDay() + "/" + currentDate.getFullYear() };
console.log($scope.model);
$scope.onCalendarChange = function() {
console.log(currentDate);
};
});
$(document).ready(function() {
$("#calendar").datepicker();
});
</script>
此代码看起来运行良好。正在调用更改事件并正确显示新的 selectedDate。
但我不断看到开发人员使用各种箍(主要是指令)来让日期选择器在 Angular 中工作的帖子。
我错过了什么吗?
【问题讨论】:
-
指令用于此目的,因此可以重复使用。每次您想在应用程序中使用 datepicker 时,您都必须复制刚刚编写的控制器。坏主意。