I've got a custom directive used to standardize date inputs and format them to match my (somewhat strange) API requirements. The tag used to invoke it is as follows:
<date-input date-id="birthDate" date-label="Date Of Birth" ng-model="client.dateOfBirth"></date-input>
I'm getting the following error:
Syntax Error: Token 'Of' is an unexpected token at column 6 of the expression [Date Of Birth] starting at [Of Birth].
When I remove the spaces (i.e date-label="DateOfBirth"
it works fine.)
How can I allow spaces in directive attributes?
The directive:
directives.directive('dateInput', [function() {
var link = function(scope, element, attrs, model) {
scope.dateLabel = attrs.dateLabel;
scope.dateId = attrs.dateId;
var dateObjectPre = moment(scope.dateObject);
scope.dateObjectPre = dateObjectPre.format('MMDDYYYY');
scope.update = function() {
var dateObject;
if(angular.isDefined(scope.dateObjectPre)) {
dateObject = moment(scope.dateObjectPre, 'MMDDYYYY');
}
if (dateObject && dateObject.isValid()) {
scope.dateObject = dateObject.format('YYYY-MM-DD');
}
else {
scope.dateObject = '';
}
};
};
return {
restrict: 'E',
link: link,
templateUrl: '/views/directives/dateInput.html',
replace: true,
scope: {
'dateLabel': '=dateLabel',
'dateObject': '=ngModel',
'dateShow': '=dateShow',
'dateRequired': '=dateRequired',
'dateId': '=dateId'
}
}
}]);
Shouldn't you be using @ when passing attribute values into directives?
scope: {
'dateLabel': '@dateLabel'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With