英文:
How remove angular selector in ng-content
问题
我有这个组件的嵌套结构
<form [formGroup]="form" novalidate autocomplete="off" (ngSubmit)="onSubmit()">
<app-form-field label="Input" [required]="true" [control]="form.controls['input']">
<app-input formControlName="input"></app-input>
</app-form-field>
</form>
如何移除app-input
的Angular选择器,只保留input
标签?
我需要这样来使用~
或>
的CSS选择器。
感谢您的帮助
英文:
I have this imbrication of component
<form [formGroup]="form" novalidate autocomplete="off" (ngSubmit)="onSubmit()">
<app-form-field label="Input" [required]="true" [control]="form.controls['input']">
<app-input formControlName="input"></app-input>
</app-form-field>
</form>
How can i remove the app-input angular selector and just keeping input tag please?
I need this for works with ~ or > css operator
Thanks for your help
答案1
得分: 1
你不能移除<app-input>
选择器,但可能有其他解决方案:
- 如果
<app-input>
中实际上没有你需要的任何逻辑,只需将其替换为原生的<input>
。只要你导入了ReactiveFormsModule
,formControlName
将在原生的<input>
标签上正常工作,你不总是需要一个组件。 - 如果你确实需要
app-input
组件- 使用后代元素上的类,而不是
>
或~
,以特定地定位你想要样式化的元素,无论它们如何嵌套
<form [formGroup]="form"> <app-form-field> <app-input formControlName="input" class="form-control"></app-input> </app-form-field> <app-form-field> <input type="checkbox" formControlName="input2" class="form-control" /> </app-form-field> <input type="radio" formControlName="input3" class="form-control" /> </form>
- 使用选择器的组合,例如
form app-form-field > *, form app-form-field app-input input { // 你的样式 }
- 使用后代元素上的类,而不是
英文:
You can't remove the <app-input>
selector, but there may be other solutions to your problem:
- If you don't actually have any logic in
<app-input>
that you need, just replace this with a native<input>
.formControlName
will work on native<input>
tags out of the box (as long as you have imported theReactiveFormsModule
), you don't always need a component - If you do have a need for the
app-input
component- Use classes on descendent elements instead of
>
or~
to specifically target the elements you want to style no matter how they are nested
<form [formGroup]="form"> <app-form-field> <app-input formControlName="input" class="form-control"></app-input> </app-form-field> <app-form-field> <input type="checkbox" formControlName="input2" class="form-control" /> </app-form-field> <input type="radio" formControlName="input3" class="form-control" /> </form>
- Use a combination of selectors, e.g.
form app-form-field > *, form app-form-field app-input input { // your style }
- Use classes on descendent elements instead of
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论