角度共享 Var 中的模板问题

  • 本文关键字:问题 共享 Var angular
  • 更新时间 :
  • 英文 :


我想知道我是否需要仅在模板标签中实现它

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 更新父组件属性

不,您不能在一个组件中使用这两个属性,使用templateUrltemplateBeacusetemplate是内联编辑,templateUrl是 html 页面内部编辑。所以你只需要选择一个。

最新更新