因为我使用的输入有很多相同的指令和.应用css类,我想将重复代码提取到如下组件:
@Component({
selector: "app-input",
template: `
<div class="...">
<input type="..." name="..." class="..." [(ngModel)]="value" someDirectives...>
<label for="...">...</label>
</div>
`,
...
})
export class InputComponent implements OnInit {
// some implementation connecting external ngModel with internal "value" one
}
这里的问题是,创建一个组件时,它可以与ngModel一起用作普通输入:
<app-input [(ngModel)]="externalValue" ... ></app-input>
我在互联网上找到了几种可能部分或完全过时的解决方案,比如: