The restrict option is typically set to:
\'A\' - only matches attribute name
\'E\' - only matches element name
\'C\' - only matches class name
\'M\' - on
Some issues in your code:
scope: { ngModel: '='}. Instead use require.ngModel.$viewValue.scope property for get a shared scope with the controller, and access directly to the answers variable through the scope passed in the link function like this scope.answers. answers variables within the isolated scope property of your directive. scope: { answers: '=' }The modified code:
function validVehicleyear($http) {
return {
restrict: 'C',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
element.bind('change', function () {
console.log('here in validVehicleyear');
$http.get('api.php' + ngModel.$viewValue)
.then(function (response) {
scope.answers.VehicleMake = response.data;
});
});
}
}
}
My final recommendation it's not use the Class option, in your case, it's better use the Attribute option. Good luck!