0

I have to click on a div that show a list of cities, when I click on one of the cities displayed I want to execute a method and display the cityName, for that my implement is so far like this:

Html of file 1

 <div [(ngModel)]="cityName" class="heads">{{cityName}}</div>

.js of file 1

@Injectable()
export class queryToDB {

  constructor(http) {
  this.http = http;
  this.valueToBeChanged = "Select a city";
  }

}

File 2:

@Component({
      template: `
        <div>
               <button ion-item *ngFor="let city of cities" (click)="switchToThisCity(city.cityName);">{{city.cityName | uppercase}}</button>
        </div>
      `,
      providers:[queryToDB]
    })


export class MyPopover{
static get parameters(){
return [[Http]];
 }


constructor(http) {
    this.http    = http;
 }

 switchToThisCity(currentCity){
  this.cityName = "New York";
  }
 }

However, I receive the below error:

EXCEPTION: No value accessor for ''

Any ideas on what's causing the issue?

1
  • where is the "cities" field? Commented Aug 11, 2016 at 21:01

1 Answer 1

2

I think you shouldn't be tried to use ngModel to two way bind on div.

Because ngModel expects to use it on an input field or any other form elements. That's why you get the No value accessor error.

You can find out more at here

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, duh, I missed that part. Ha Hoang is right, you can't use ngModel (two way data binding) on a control that can only have one way data binding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.