简体   繁体   English

没有用于未指定名称属性Angular 2的表单控件的值访问器

[英]No value accessor for form control with unspecified name attribute Angular 2

I'm using ng2-select Click here ! 我正在使用ng2-select单击此处 lib but this error is show : lib,但显示此错误:

No value accessor for form control with unspecified name attribute 没有用于具有未指定名称属性的表单控件的值访问器

  • using angular2 使用angular2
  • in html file same as link in top 在html文件中,与顶部的链接相同
  • in ts my component same as link in top 在我的组件与顶部的链接相同
  • in modules.ts add : import { SelectModule } from 'ng2-select'; 在modules.ts中添加:从'ng2-select'导入{SelectModule}; and : imports :[ SelectModule , ] 和:imports:[SelectModule,]

Can anyone help me to fix this error plz ? 谁能帮我解决此错误plz?

 <div style="width: 300px; margin-bottom: 20px;">
 <h3>Select a single city</h3>
 <ng-select [allowClear]="true"
          [items]="items"
          [disabled]="disabled"
          (data)="refreshValue($event)"
          (selected)="selected($event)"
          (removed)="removed($event)"
          (typed)="typed($event)"
          placeholder="No city selected">
</ng-select>
<p></p>
<pre>{{value.text}}</pre>
<div>
  <button type="button" class="btn btn-primary"
        [(ngModel)]="disabledV" btnCheckbox
        btnCheckboxTrue="1" btnCheckboxFalse="0">
  {{disabled === '1' ? 'Enable' : 'Disable'}}
   </button>
  </div>
</div>

in ts compmonent: 在ts中:

 import { Component, OnInit } from '@angular/core';
 import { SelectItem } from 'ng-select/ng2-select'
 @Component({
  selector: 'app-api-two',
  templateUrl: './api-two.component.html',
  styleUrls: ['./api-two.component.css'],
 })
  export class ApiTwoComponent implements OnInit {

  constructor() { }

 ngOnInit() {
 }
  public items:Array<string> = ['Amsterdam', 'Antwerp', 'Athens', 
   'Barcelona',
  'Berlin', 'Birmingham', 'Bradford', 'Bremen', 'Brussels', 'Bucharest',
  'Budapest', 'Cologne', 'Copenhagen', 'Dortmund', 'Dresden', 'Dublin',
  'Düsseldorf', 'Essen', 'Frankfurt', 'Genoa', 'Glasgow', 'Gothenburg',
  'Hamburg', 'Hannover', 'Helsinki', 'Kraków', 'Leeds', 'Leipzig', 'Lisbon',
  'London', 'Madrid', 'Manchester', 'Marseille', 'Milan', 'Munich', 
   'Málaga',
  'Naples', 'Palermo', 'Paris', 'Poznań', 'Prague', 'Riga', 'Rome',
  'Rotterdam', 'Seville', 'Sheffield', 'Sofia', 'Stockholm', 'Stuttgart',
  'The Hague', 'Turin', 'Valencia', 'Vienna', 'Vilnius', 'Warsaw', 
  'Wrocław',
  'Zagreb', 'Zaragoza', 'Łódź'];

private value:any = {};
public valueName:string='';
private _disabledV:string = '0';
private disabled:boolean = false;

private get disabledV():string {
  return this._disabledV;
}

private set disabledV(value:string) {
  this._disabledV = value;
  this.disabled = this._disabledV === '1';
}

public selected(value:any):void {
  console.log('Selected value is: ', value);
}

public removed(value:any):void {
  console.log('Removed value is: ', value);
}

public typed(value:any):void {
  console.log('New search input: ', value);
}

public refreshValue(value:any):void {
  this.value = value;
}
}

Thanks You. 谢谢。

You should add the ngDefaultControl attribute to your input like this: 您应该像这样将ngDefaultControl属性添加到您的输入中:

<div>
  <button type="button" class="btn btn-primary"
        [(ngModel)]="disabledV" btnCheckbox
        btnCheckboxTrue="1" btnCheckboxFalse="0" ngDefaultControl>
        {{disabled === '1' ? 'Enable' : 'Disable'}}
   </button>
 </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 7-具有未指定名称属性的表单控件无值访问器 - Angular 7 - No value accessor for form control with unspecified name attribute Angular 7 Reactive 表单“没有未指定名称属性的表单控件的值访问器” - Angular 7 Reactive forms “No value accessor for form control with unspecified name attribute” 没有用于角度控制的格式控件的值访问器(角度5中具有未指定的名称属性) - No value accessor for form control with unspecified name attribute in angular 5 以Angular格式显示img会显示“没有用于未指定名称属性的窗体控制的值访问器” - Displaying img in Angular form gives “No value accessor for form control with unspecified name attribute” 没有用于ngControl的未指定名称属性的表单控件的值访问器 - No value accessor for form control with unspecified name attribute for ngControl ERROR 错误:在开关上没有具有未指定名称属性的表单控件的值访问器 - ERROR Error: No value accessor for form control with unspecified name attribute on switch 错误错误:具有未指定名称属性的表单控件没有值访问器 - ERROR Error: No value accessor for form control with unspecified name attribute 有角材料Datepicker引发多个自定义值访问器将表单控件与未指定名称属性相匹配 - Angular material Datepicker throws More than one custom value accessor matches form control with unspecified name attribute ERROR 错误:在 angular 中绑定轮播时,没有具有未指定名称属性的表单控件的值访问器 - ERROR Error: No value accessor for form control with unspecified name attribute when bind carousel in angular 表单控件错误:错误错误:没有具有未指定名称属性的表单控件的值访问器 - form control error:ERROR Error: No value accessor for form control with unspecified name attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM