My goal is to minimize the code using the Angular translate pipe. Currently, I have to use 8 curly brackets and write "translate" twice... a better way must exist.
My current code looks like:
<span
*ngIf="checkoutForm.get('email')?.errors?.['email']">
{{ 'eMail' | translate }} {{ lowerCaseFirstLetter('isInvalid' | translate) }}
</span>
And I'm trying to do shorten it in something like
<span
*ngIf="checkoutForm.get('email')?.errors?.['email']"
translate>eMail {{ lowerCaseFirstLetter('isInvalid' | translate) }}
</span>
or maybe even
<span
*ngIf="checkoutForm.get('email')?.errors?.['email']"
translate>eMail lowerCaseFirstLetter('isInvalid')
</span>
The Text
email is a translation = E-Mail
isInvalid is a translation = Is invalid
lowerCaseFirstLetter() is a function which just lowercases first letter this is important to not destroy the orthography in other languages
You could create a custom pipe that accepts an extra parameter so you can do this:
for that create a pipe file
error.pipe.tswith following content:declare it in the component module you want to use it in
example.module.ts:now you can do following thing in the component: