Angular 5.2:类型组件上不存在错误属性



我已经将Formbuilder.Group方法中的属性添加为(ts代码(:

this.form = this.fb.group({          
        caseNumber: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(50), Validators.pattern('^[a-zA-Z0-9]*$')]],
        userName: ['', [Validators.required]],

信息接口 ts 文件 :

   export interface Information {
    userName : string 
    caseNumber: string
}

我正在使用补丁值方法将值作为(ts代码(将值定位为变量:

Info: Information;
         this.form.patchValue({
            caseNumber: this.Info.caseNumber,
            userName: this.jsonArrayvalues(this.Info.userName, this.dropdownListForUserName),

此外,我在html文件中将这些属性用作:

 <div class="form-group padding-top-bottom" [ngClass]="{'has-error': (form.get('userName').touched ||
                                              form.get('userName').dirty) &&
                                              !form.get('userName').valid }">
                                <label class="col-md-4" for="firstNameId"><span tooltip={{attributeNames.userNameTitle}} data-placement="right">Vendor Name</span></label>
                                <div class="col-md-7">
                                    <ng-select [items]="userName"
                                               multiple="true"
                                               [addTag]="true"
                                               bindLabel="itemName"
                                               (change)="onItemSelect($event,'user','userName')"
                                               formControlName="userName"
                                               [(ngModel)]="userName">
                                    </ng-select>

但是当我运行命令ng build --prod时,我收到以下错误:

src\app\componentsewew.component.html(161,48( 中的错误:类型">NewComponent"上不存在属性">用户名"。

命令 ng 构建同样有效

<ng-select [items]="userName"
...
</ng-select>

需要 items 属性的数组(我在您发布的代码中没有看到(。

顺便说一下,你应该称它为"用户名",因为它应该是一个数组。

<ng-select [items]="userNames" //!!! array
...
</ng-select>

最新更新