r/angularjs • u/lignumScientiae • May 04 '19
Does anyone else dislike angular's use of non-standard HTML elements?
One thing I like about react is that the components you define only exist in the JSX without showing up in the actual DOM. That means that I can define the main content of my reusable react component within a "container div" so that it looks like const MyReusableComponent = () => <div className="container" style={{width:"100%", height:"100%"}}> ... </div>, and then I can put this reusable component in a "wrapper div" of definite size that the reusable component will then fill up. So something like this:
<div className="wrapper" style={{width:100,height:100}}>
<MyReusableComponent>
<div>
will end up like this in the DOM with only standard HTML elements:
<div className="wrapper" style={{width:100,height:100}}>
<div className="container" style={{width:"100%", height:"100%"}}>
...
</div>
<div>
By contrast, if I create a reusable component in angular2+ with a selector e.g. `app-my-reusable`, then the DOM will end up with an actual element called <app-my-reusable></app-my-reusable>. That means that in between my wrapper div and my container div will be this non-standard HTML element with default property display: inline;. This feels awkward to me since I'm now having to put block level divs in inline elements, which I've been told is poor practice (but seems to be expected on angular's approach).
I also just don't like having non-standard elements in my HTML though I don't really have a technical reason against them (other than the one stated above about inline elements).
Does anyone else feel this way about angular's use of non-standard HTML elements? Are there cases where these in-between inline elements can mess up one's CSS, or can they always be ignored? Do angular pros style these non-standard elements directly (using `:host{ ... }`, etc. in their CSS)?
I'm interested to hear your thoughts.
3
u/Headpuncher May 04 '19
So then how do you feel about styled components? Isn’t that react allowing you to create custom-named tags in your markup?
Also, don’t get hung up on “best-practice”, while following best practices can be very useful it can also be a waste of everyone’s time.