【发布时间】:2018-10-26 01:28:55
【问题描述】:
我想知道是否只需要在模板标签中实现这个
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 in child component updates parent component property
【问题讨论】:
-
您不能在同一个组件中同时使用
templateUrl和template。您必须使用templateUrl或template。区别在于templateUrl的情况下,您在.ts文件之外写入html template,而在template的情况下,您将html template写为.ts内部的字符串。否则就没什么区别了 -
是的,你需要将它插入'transaction.component.html',并且你必须从'@angular/forms'导入import {FormsModule};
标签: angular