2

I'm trying to bind countries data into my px-component which is a typeahead.

Codepen link here.

On binding the data directly in html the typeahead is suggesting the list of countries. But when I try the same by passing data from class its not binding.

var AppComponent = ng
  .Component({
    selector: 'my-app'
  })
  .View({
    template: `<div> 
<h3>Case 1 : Working dropdown:</h3>
<px-typeahead placeholder="Enter your search query" local-candidates='["Alabama","Alaska","American Samoa","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District Of Columbia", "South Dakota","Tennessee","Texas","Utah","Vermont","Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'></px-typeahead> 
<br>
<h3>Case 2 : Not working dropdown if data is bind from controller:</h3>
    <px-typeahead placeholder="Enter your search query" local-candidates={{countries}}></px-typeahead> 
{{countries}}
    </div>`
  })
  .Class({
    constructor: function() {      
       this.countries=["United States", "Antigua and/or Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan"]
    }
  });

Think the component px-typeahead is expecting the data in its attribute local-candidates to be an array with ''. I tried different ways of binding countries like {{countries}},"countries" etc.But didn't work.

2
  • What is <px-typeahead> ?? its your one of the component selector name ? Commented Sep 15, 2017 at 9:35
  • @Chandru Its a component Commented Sep 15, 2017 at 10:02

1 Answer 1

1

The correct syntax (for two-way data binding) is [local-candidates]="countries", which will work in your CodePen.

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

2 Comments

Did you read I tried different ways of binding countries like {{countries}},"countries" etc but didn't work. from the OP question? So you should clarify with OP in comment before answering.
Ehm why? Yea of course i read it and both ways he mention don't work with two-way data-binding. What am i discussing here iwth you? Comments are for dicussing the question, not for answering. if the answer would have been off-topic (for example if the OP asks something but the answer would be a different topic) then i would understand your concerns, but its just a plain simple answer to a simple question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.