feat(compiler-cli): detect missing control flow directive imports by AndrewKushnir · Pull Request #46146 · angular/angular
@Harpush right, suggestion about a NgModule to import is one aspect of it. When it comes to the "directive didn't match", the situation is more nuanced. #37322 talks about the specific situation: <div *something>. In compiler this will de-sugar to <ng-template something>.
Now the question we should ask: what is the meaning of something? It is reasonable to have 2 different takes on it:
- we expect that
somethingis an attribute on which at least one directive should match - if there are no matching directives we should error - this is what you are suggesting; - we assume that
somethingis just a random attribute on which a directive can match - but is not required to. Such an attribute could be used for content projection, for example.
As we see the (2) usage in the wild we don't have much choice but, at this point, assume the (2) meaning. This is why we can't error on seeing <div *something> without a matching directive... I know that this is not ideal and might be confusing - but this is something we need to take into account when evolving a framework that has lots of existing code depending on it.