I am working on an Angular 7/8 application. I have made a custom input
component and its selector is called <app-input></app-input>
. This input
has some specific stylings that I may want to change somewhere else for example, by default the border-color
is blue
, and in another component, I want to change its style to red
. The problem is I am unable to access the input
element within the <app-input></app-input>
.
In the parent component, I am applying the styles as :
I am Using SCSS
//Styles from parent component
app-input{
& .an-input{
width: 100%;
& input{
border-color: red;
}
}
}
The Input <app-input></app-input>
component code
//Template
<div class="an-input">
<input
[type]="type"
[id]="id"
[name]="name"
(focus)="inputFocus($event)"
(blur)="inputBlur($event)"
(input)="userTyping($event)"
class="an-input-el"
/>
<label [for]="id">
{{label}}
</label>
</div>
//Styles
.an-input{
display: inline-block;
position: relative;
width: 100%;
margin-bottom: 30px;
& input, & textarea{
padding: 15px;
color: $an-color;
border: none;
outline: none;
border: 2px solid $font-darker;
border-radius: 2px;
width: 100%;
&.input-fly{
border-color: $an-color;
}
&.input-fly-error{
border-color: maroon;
}
}
& label{
position: absolute;
left: 0;
padding: 0 10px;
font-size: 13px;
transition: .1s;
cursor: text;
color: $font-darker;
font-size: 11px;
&.label-fly{
padding: 0px;
color: $an-color;
}
}
}