我想知道我是否需要仅在模板标签中实现它
template: ` <p>Child: {{sharedVar}}</p>
<input [(ngModel)]="sharedVar"
(ngModelChange)="change()">
。因为在我的组件中,我有
@Component({
selector: 'app-transaction',
templateUrl: './transaction.component.html',
styleUrls: ['./transaction.component.scss', ],
})
喜欢这个。我可以直接在我的 html 中实现它吗
我从 -
子组件中的 Angular 2 ngModel 更新父组件属性
不,您不能在一个组件中使用这两个属性,使用templateUrl
或template
Beacusetemplate
是内联编辑,templateUrl
是 html 页面内部编辑。所以你只需要选择一个。