【发布时间】:2016-10-22 04:09:26
【问题描述】:
我在 nativescript 中构建一个组件,我收到以下错误“没有用于具有未指定名称属性的表单控件的值访问器”
我正在做同样的事情,我觉得我在其他组件中没有问题,所以我不明白为什么它不起作用。
首先,这里是来自friend.component.ts的相关代码:
import { Component, ElementRef, ViewChild } from "@angular/core";
import { TextField } from "ui/text-field";
@Component({
selector: "Friends",
templateUrl: "controller/friend/friend.component.xhtml",
})
export class FriendComponent
{
friendName: string;
@ViewChild("friendNameTextField") friendNameTextField: ElementRef;
constructor() {
this.friendName = "";
}
}
这是来自 controller/friend/friend.component.xhtml 的代码
<GridLayout rows="auto, *">
<GridLayout row="0" columns="*, auto">
<Textfield col="0" #friendNameTextField [(ngModel)]="friendName" hint="Search for friend"></Textfield>
<Label col="1" text="+ Add Friend" (tap)="addFriend()"></Label>
</GridLayout>
</GridLayout>
我读到如果不包含 NativeScriptFormsModule 可能会发生这种情况,但我在 app.module.ts 中有这个:
import { NativeScriptFormsModule } from "nativescript-angular/forms";
@NgModule({
imports: [
NativeScriptModule,
NativeScriptFormsModule,
NativeScriptHttpModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes)
],
declarations: [
AppComponent,
...navigatableComponents,
],
bootstrap: [AppComponent],
})
export class AppModule {}
我已经从中删除了一些代码,而且我对 Nativescript 还是很陌生,所以我可能遗漏了一些相关的东西。如果我遗漏了什么,请告诉我您还需要什么,我会发布它。
谢谢。
【问题讨论】:
标签: nativescript angular2-nativescript