0

This is my 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>

This is my controller

$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" },
]

This is my directive

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'
                    }
                }

            });
        });
    }
}

})

I want to send the value of "scope.months.disabled" from the directive to the front end "ng-disabled="month.disabled"" and disable the checkboxes as per the logic

  • try - http://stackoverflow.com/questions/13318726/easiest-way-to-pass-an-angularjs-scope-variable-from-directive-to-controller – Itsik Mauyhas Jun 09 '16 at 13:21
  • What is the purpose of putting this code in a directive rather than just handling it in your controller? All you are doing is updating the model, you're not manipulating the DOM – jbrown Jun 09 '16 at 14:31

0 Answers0