我正在尝试绑定变量,方法和双向绑定。但是在所有3个上都会出错。下面是代码:
.html
<ion-label class="banner_small" [ngModel]="getUserName()"></ion-label>
.ts
getUserName() {
return "test";
}
错误是:
ERROR ReferenceError: $event is not defined
.html
<ion-label class="banner_small" [ngModel]="userName"></ion-label>
.ts
export class MyApp {
public userName: string;
constructor(...){
this.userName = "test";
...
}
错误是:
Error: No value accessor for form control with unspecified name attribute
.html
<ion-label class="banner_small" [(ngModel)]="getUserName()"></ion-label>
.ts
getUserName() {
return "test";
}
错误是:
Uncaught Error: Template parse errors:Parser Error: Unexpected token '=' at column 14 in [getUserName()=$event]
答案 0 :(得分:0)
第一个Mistkae,您尝试在标签上使用ngModel,应在输入上使用ngModel
如果您只想绑定到标签,只需使用 [innerHtml]
<ion-label class="banner_small" [innerHtml]="getUserName()"></ion-label>