简体   繁体   中英

Angular js ng-disabled

I couldn't solve this problem, I need help, here's my problem;

I have checkbox inputs as days(mon,tue,wed,thu,fri,sat,sun) and select options shifts(breakfast,lunch,dinner)

What I try to do is,

For example

If you select "mon" while "breakfast" selected: other "mon"s at other breakfast's line must be disabled, but not the one you select.

Here's my code:

day.html: focus on ----? part.

<label class="btn btn-info btn-sm {{ dayName }}">
    <input type="checkbox" name="{{ dayName }}" 
    ng-model="dayName" ng-disabled="?----dayName----?">
</label>

controller has:

$scope.days = ["pzt","sal","car","per","cum","cmt","pzr"]

directive:

app.directive("day", function () {
    return {
        restrict: "E",
        scope: {
            dayName: "@"
        },
        templateUrl: "/static/templates/settings/day.html"
    }
})

html:

<div class="form-group" style="margin-bottom:0;">
    <div class="btn-group" data-toggle="buttons">
        <day ng-repeat="d in days" data-id="breakfast" dayName="{{d}}"></day>
    </div>
</div>

<div class="form-group" style="margin-bottom:0;">
    <div class="btn-group" data-toggle="buttons">
        <day ng-repeat="d in days" data-id="breakfast" dayName="{{d}}"></day>
    </div>
</div>

You can add conditions to ng-disabled like this:

<label class="btn btn-info btn-sm {{ dayName }}">
    <input type="checkbox" name="{{ dayName }}" 
    ng-model="dayName" ng-disabled="dayName == 'mon' && breakfast">
</label>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM