In an Angular app, I am looking for a way to force a variable in TypeScript to be a valid HTML template, so that this will be compiled successfully:
let v = '<div>bla…</div>'
but this:
let v = '<cc></div>'
will cause a compilation error.
Is there such a possibility?
Edited:
If there is no way at compile time, maybe there is a way to make the Angular Cli Builder crash at build time in this case?
Not sure if it is possible to validate html strings at compile time.
Here is how to check validity of html at runtime Check if HTML snippet is valid with JavaScript
Depending on your use case, you may also need to sanitize html or bypass sanitizer, using https://angular.io/api/platform-browser/DomSanitizer