这是我的HTML
<div ng-repeat=" month in months track by $index" ng-hide="fromdate == '' || todate =='' ||option != 'Yearly'">
<input class="toBeChecked" type="checkbox" ng-disabled="month.disabled" checker-directive>
<label ng-bind="month.Name"></label>
</div>
这是我的控制器
$scope.months = [
{ "disabled": "false", "Name": "January" },
{ "disabled": "false", "Name": "February" },
{ "disabled": "false", "Name": "March" },
{ "disabled": "false", "Name": "April" },
{ "disabled": "false", "Name": "May" },
{ "disabled": "false", "Name": "June" },
{ "disabled": "false", "Name": "July" },
{ "disabled": "false", "Name": "August" },
{ "disabled": "false", "Name": "September" },
{ "disabled": "false", "Name": "October" },
{ "disabled": "false", "Name": "November" },
{ "disabled": "false", "Name": "December" },
]
这是我的指示
app.directive('monthDirective', function () {
return {
restrict: 'A',
link: function (scope, elem) {
var fromDate , toDate;
scope.$watch('fromdate', function (newValue, oldValue) {
fromDate = new Date(newValue);
fromDate = moment(newValue, 'YYYY-MM-DD');
console.log('newValue', newValue)
});
scope.$watch('todate', function (newValue, oldValue) {
toDate = new Date(newValue);
toDate = moment(newValue, 'YYYY-MM-DD');
var range = moment.range(fromDate, toDate);
range.by('months', function (moment) {
var monthArray = moment.toArray('months');
for (var i = 0; i <= scope.months.length; i++)
{
var status = false;
if (i == monthArray[1]) {
status = true;
}
if(status)
{
// $('.toBeChecked').prop('disabled', false);
console.log('TrueStatus', scope.months.disabled)
scope.months.disabled = 'false'
}
else
{
//$('.toBeChecked').prop('disabled', true);
console.log('FalseStatus', scope.months.disabled)
scope.months.disabled = 'true'
}
}
});
});
}
}
})
我想发送&#34; scope.months.disabled&#34;的值。从指令到前端&#34; ng-disabled =&#34; month.disabled&#34;&#34;并根据逻辑
禁用复选框