我在一个页面上有一个简单的setcalender指令,它工作正常。但是,如果我转到另一页然后再回来,压延机就不再显示了。以下是指令代码。我在渲染之前是否缺少清理范围或什么?
HTML代码
<div>
<label>Date</label>
<input type="text" ng-model="date" setcalendar>
</div>
自定义指令
angular.module("myapp").directive("setcalendar", function () {
debugger;
return {
restrict: 'A',
require: 'ngModel',
scope: {},
link: function (scope, element, attrs) {
scope.$watch(attrs.datepicker, function () {
$(element).datepicker({
dateFormat: 'mm/dd/yy',
mode: 'single',
changeMonth: true,
changeYear: true,
showOn: "button",
buttonImage: "Content/images/Cal.png",
buttonImageOnly: true,
class:"calendar",
onSelect: function (dateText) {
var expression = attrs.ngModel + " = " +
"'" + dateText + "'";
scope.$apply(expression);
}
});
});
}
}
});