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:
<label class="typ3">Enable INKWRX Login:</label>
<dw-checkbox class="notarylogin" name="UserHasPassword" ng-model="user.Details.HasPassword" ></dw-checkbox>
<label class="typ3">Notary:</label>
<dw-checkbox name="notary" id="notary" ng-model="user.ExtraData.userPermissions.notary.allowed" ng-click="amendNotary(user.ExtraData.userPermissions.notary.allowed)"></dw-checkbox>
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: '<input name="name" type="checkbox" ng-model="model" />',
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?