I'm in the process of developing an AngularJS directive that utilizes the attribute-flag selected
, which serves as both the initial state and potentially a current value.
Is there a way to incorporate a validation step within the AngularJS directive to verify if the attribute can receive a value before actually assigning one?
app.directive('customControl', [function () {
return {
restrict: 'E',
scope: {
selected: '=?', // optional, represents initial + current selected state;
},
templateUrl: 'views/directives/customControl.html',
link: function (scope, elem, attr) {
if (/* validate if scope.selected can be assigned a value */) {
scope.selected = /* assigned value */;
}
}
};
}]);