使用AOT编译时Angular 9无法绑定

时间:2020-03-02 11:26:07

标签: angular

正常进行ng build即可。当我做ng build --aot时,我收到许多错误。尽管主要的是以下内容,但我希望其他人有类似的答案:

错误NG8002:由于它不是'input'的已知属性,因此无法绑定到'ngModel'

[(ngModel)] =“值”

我的ts文件中有:

import { NgModel } from '@angular/forms';
    
@Component({
      selector: 'stock-input',
      template: `
          <input
            id="stockid"
            type="text"
            class="form-control"
            name="stockid"
            maxlength="13"
            [(ngModel)]="value"
            (blur)="touch()"
            (keyup)="change()"
            (change)="change()"
            #autofocus
          />
      `,

无论到哪里看,它都表示我应该引用FormsModule和ReactiveFormsModule。两者都导入了我的app.module.ts文件中。

1 个答案:

答案 0 :(得分:1)

似乎无法以这种方式设置模板中声明的内联html。将html放入自己的文件中,并以以下形式引用:

template: './mytemplatename.html',

解决了ng build --aot问题。