链接以查看我的问题的可视化链接
我完全迷路了。已阅读大量 SO 回复(最接近的问题在这里)
html:
<div title="Employment start date"
ng-model="tabsData.employment_start_date"
input-date="{{dateFormats.getCurFormat()}}"></div>
我需要显示和编辑(通过自定义指令)日期值;
如何将我的OUTER ng-model ( tabsData.employment_start_date ) 与INNER ng-model ( ??? )绑定(双向) <datepicker>
?
(请参阅下面<---------- HERE !!!
的标记标记到我需要通过双向绑定的片段中<datepicker>
的ng-model attr)
有某种指令:
directive('inputDate', function factory(dateFilter) {
return {
require:'^ngModel',
restrict:'A',
replace: true,
template:'<div class="control-group">
<div class="controls">
<label>{{title}}</label>
<input class="dateInputValue"
ng-model="formattedDate"
readonly
ng-click="showPicker=!showPicker"/>
<div class="datePickerBlock">
<button class="datePickerBtn"
ng-click="showPicker=!showPicker">
<i class="whhg icon-calendar"></i>
</button>
<datepicker
class="datePicker"
show-hide="{{showPicker}}"
ng-model=" ??? " <--------------------- HERE !!!!
show-weeks="true"
starting-day="1"
date-disabled="disabled(date, mode)">
</datepicker>
</div>
</div>
</div>',
link:function (scope, elm, attrs, ngModelCtrl) {
ngModelCtrl.$formatters.unshift(function (modelValue) {
scope.formattedDate = dateFilter(modelValue, attrs.inputDate || 'medium');
return scope.formattedDate;
});
ngModelCtrl.$parsers.unshift(function(viewValue) {
var date = new Date(viewValue);
return isNaN(date) ? '' : date;
});
}
};
});
除了我的第二个问题,为什么当我将模板替换为templateUrl属性时:
templateUrl: '/cached/ui-elements/inputBool.html'
引用:
/* Template */
angular.module("/cached/ui-elements/inputDate.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("/cached/ui-elements/inputDate.html",
"<div class=\"controls\">\n"+
"<input class=\"dateInputValue\" " +
"ng-model=\"ngModelLocal\" " +
"readonly " +
"ng-click=\"showPicker=!showPicker\"/>\n"+
<MY-DATEPICKER ng-model="ngModelLocal"></MY-DATEPICKER>
"</div>"
}]);
attrs.dateFormat等于{{dateFormats.getCurFormat()}}
STRING!(没有像以前使用模板属性在 $scope 上返回实际的表达式执行结果)
伙计们帮助;)