Class' NgForm'没有实例获取者'用户'

时间:2016-11-11 13:46:37

标签: angular dart

我正在尝试基于angular2dart构建表单。

组件类:

    @Component(
        selector: 'start-app',
        directives: const[materialInputDirectives],
        styleUrls: const ['login_component.css'],
        templateUrl: 'login_component.html')
    class LoginComponent {

      String scaleImg = 'packages/wp_login/assets/scale.svg';
      Login login = new Login();

      onSubmit() {
        print('Submit');
      }

    }

和模板:

<div class="container">
    <div class="row">
        <div class="image">
            <img [src]="scaleImg">
        </div>
        <div class="forms">
            <form (ngSubmit)="onSubmit()" #login="ngForm">
                <div>
                    <material-input type="text" label="User" [(ngModel)]="login.user"></material-input>
                </div>
                <div>
                    <material-input type="password" label="Password" [(ngModel)]="login.password"></material-input>
                </div>
                <div>
                    <material-input type="text" label="Language" [(ngModel)]="login.language"></material-input>
                </div>
                <div>

                </div>

            </form>
        </div>
    </div>
</div>

我得到了错误:

enter image description here

我做错了什么?

1 个答案:

答案 0 :(得分:3)

 #login="ngForm"

创建一个引用login指令的模板变量NgForm

[(ngModel)]="login.user"

失败,因为login引用了#login="ngForm" template variable and the error message is right about that it doesn't have a property用户。

您需要重命名模板变量或组件的属性。