Tying the enablement of one checkbox to another using AngularJS and jQuery I'm new to AngularJS, coming from a jQuery background and I have a situation I've solved but only by including jQuery in an AngularJS function.  Something just doesn't feel right doing this and I was hoping someone could tell me if there's a better way. (This is all code I have inherited and have amended to enable new functionality)

I have 2 checkboxes, let's call them 'Notary' and 'Login'. If I enable Notary, then Login must get enabled and also disabled so the user can't uncheck it.

The ASPX looks like:

 &lt;label class="typ3"&gt;Enable INKWRX Login:&lt;/label&gt;
 &lt;dw-checkbox class="notarylogin" name="UserHasPassword" ng-model="user.Details.HasPassword" &gt;&lt;/dw-checkbox&gt;

&lt;label class="typ3"&gt;Notary:&lt;/label&gt;
&lt;dw-checkbox name="notary" id="notary" ng-model="user.ExtraData.userPermissions.notary.allowed" ng-click="amendNotary(user.ExtraData.userPermissions.notary.allowed)"&gt;&lt;/dw-checkbox&gt;


When the dw-checkbox directive is invoked, it renders a checkbox input element for each dw-checkbox tag like this:

 //this directive adds behaviour for showing ticks and cross images in viewMode and an editable checkbox in editmode
    app.directive("dwCheckbox", function ($rootScope) {
        return {
            restict: 'E',
            require: 'ngModel',
            template: '&lt;input name="name" type="checkbox" ng-model="model" /&gt;',
            scope: {
                model: '=ngModel',
                name: '=name'
            },
            link: function (scope, element, attrs, ngModel) {

                //render the field according to the mode and the current value of the model
                function render() { ...does the rendering..}


and my amendNotary function which does the checkbox disabling looks like this (I amended another directive to add an inklogin class to the Login checkbox):

$scope.amendNotary = function(value) {
       if (value === true) {
           $scope.user.Details.HasPassword = true;
           $('.inklogin').attr('disabled', true);
       } else {
           $scope.user.SignatureText = "Signature:";
           $('.inklogin').attr('disabled', false);
       }
    }


Is there an obvious cleaner way of doing this, or is mixing jQuery with Angular generally regarded as okay?
Is there an obvious cleaner way of doing this [?]


Without knowing where the element(s) with class name inklogin exist, it can only be presumed that it exists as a child of the element with ng-controller="controller" (or however the controller is named). If that is incorrect, please update your post to include that HTML output (from the ASPX code).

Given the presumption above, jQuery can be eliminated by adding ng-disabled (bound to user.ExtraData.userPermissions.notary.allowed) to the input with class inklogin. Bearing in mind that you stated you attempted this, perhaps there was something wrong with the setup. Below is a working example of this:



angular.module('app', [])
  .controller('ctrl', function($scope) {
    $scope.user = {
      Details: {},
      SignatureText: ''
    };
    $scope.amendNotary = function(value) {
      if (value === true) {
        $scope.user.Details.HasPassword = true;
      } else {
        $scope.user.SignatureText = "Signature:";
      }
    };
  }).directive("dwCheckbox", function($rootScope) {
    return {
      restict: 'E',
      require: 'ngModel',
      template: '&lt;input name="name" type="checkbox" ng-model="model" /&gt;',
      scope: {
        model: '=ngModel',
        name: '=name'
      },
      link: function(scope, element, attrs, ngModel) {

        //render the field according to the mode and the current value of the model
        function render() {};
      }
    };
  });
&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"&gt;&lt;/script&gt;
&lt;div ng-app="app" ng-controller="ctrl"&gt;
  &lt;label class="typ3"&gt;Enable INKWRX Login:&lt;/label&gt;
  &lt;dw-checkbox class="notarylogin" name="UserHasPassword" ng-model="user.Details.HasPassword"&gt;&lt;/dw-checkbox&gt;

  &lt;label class="typ3"&gt;Notary:&lt;/label&gt;
  &lt;dw-checkbox name="notary" id="notary" ng-model="user.ExtraData.userPermissions.notary.allowed" ng-click="amendNotary(user.ExtraData.userPermissions.notary.allowed)"&gt;&lt;/dw-checkbox&gt;

  &lt;h4&gt;Signature Text:&lt;/h4&gt;
  &lt;div ng-bind="user.SignatureText"&gt;&lt;/div&gt;
  Element with class "inklogin":
  &lt;input type="checkbox" class="inklogin" ng-disabled="user.ExtraData.userPermissions.notary.allowed" /&gt;
&lt;/div&gt;





  or is mixing jQuery with Angular generally regarded as okay?


Generally it is acceptable, though each library requires extra resources (e.g. download size, time, etc.). There are whole websites about removing the need for jQuery, like http://youmightnotneedjquery.com/. if you were working on a team, some teammates might prefer to have as few libraries as possible