title: TypeError: Cannot read property 'indexOf' of undefined and Cannot read property 'toLowerCase' of undefined
body: <p>I am using autocomplete field of primeng component for entering country data.I imported all modules which are required but I got error as:</p>
  
  <blockquote>
    <p>Cannot read property 'toLowerCase' of undefined. </p>
  </blockquote>
  
  <p>I am not able to find what is missing? After removing <code>toLowerCase()</code> method I got another error as:</p>
  
  <blockquote>
    <p>Cannot read property 'indexOf' of undefined.</p>
  </blockquote>
  
  <p>Please help me to solve these error and here I am using contact component in form component.</p>
  
  <p>contactform.component.ts</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import * as jwt from 'angular2-jwt/angular2-jwt';
  import { CardModule } from 'primeng/card';
  import { CalendarModule } from 'primeng/calendar';
  import { ScrollPanelModule } from 'primeng/scrollpanel';
  import { Response } from '@angular/http/src/static_response';
  import {SelectItem} from 'primeng/api';
  import { CountryService } from './country-list.service';
  
  @Component({ 
    moduleId: module.id,
    selector: 'sd-contactform',
    templateUrl: 'contactform.component.html',
    styleUrls: ['contactform.component.css']
  })
  export class ContactFormComponent implements OnInit {
      country: any;
  
    filteredCountriesSingle: any[];
  
    constructor(private countryService: CountryService) { }
  
    filterCountrySingle(event) {
        let query = event.query;
        this.countryService.getCountries().then(countries =&gt; {
            this.filteredCountriesSingle = this.filterCountry(query, countries);
        });
    }
  
    filterCountry(query, countries: any[]):any[] {
      //in a real application, make a request to a remote url with the query and return filtered results, for demo we filter at client side
      let filtered : any[] = [];
      for(let i = 0; i &lt; countries.length; i++) {
          let country = countries[i];
          if(country.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
              filtered.push(country);
          }
      }
      return filtered;
  }
  
  }
  </code></pre>
  
  <p>Country-list.service.ts</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  import { Observable } from 'rxjs/Observable';
  // import 'rxjs/add/operator/do';  // for debugging
  
  /**
   * This class provides the NameList service with methods to read names and add names.
   */
  @Injectable()
  export class CountryService {
  
    constructor(private http: HttpClient) {}
  
    getCountries() {
        return this.http.get('app/form/country.json')
                    .toPromise()
                    .then(res =&gt; &lt;any[]&gt; res)
                    .then(data =&gt; { return data; });
    }
  }
  </code></pre>
  
  <p>contact.component.html</p>
  
  <pre><code>&lt;p-autoComplete [(ngModel)]="country" [suggestions]="filteredCountriesSingle" (completeMethod)="filterCountrySingle($event)" field="name" [size]="auto"
                              placeholder="Country" [minLength]="1" name="something"&gt;&lt;/p-autoComplete&gt;    
  </code></pre>
  
  <p>form.module.ts</p>
  
  <pre><code>import { NgModule } from '@angular/core';
  import { CommonModule } from '@angular/common';
  import { FormComponent } from './form.component';
  import { FormRoutingModule } from './form-routing.module';
  import { SharedModule } from '../shared/shared.module';
  import {TabViewModule} from 'primeng/tabview';
  import {CardModule} from 'primeng/card';
  import { DemographicFormComponent } from './demographicform.component';
  import { ContactFormComponent } from './contactform.component';
  import { EducationFormComponent } from './educationform.component';
  import { SkillActivityFormComponent } from './skillactivityform.component';
  import { EmployerDetailFormComponent } from './employerdetailform.component';
  import { ProjectFormComponent } from './projectform.component';
  import { VoluenteeringExpformFormComponent } from './volunteeringExpform.component';
  import { CertificationFormComponent } from './certificationform.component';
  import { CourseFormComponent } from './courseform.component';
  import { HonorAwardFormComponent } from './honorawardform.component';
  import { LanguageFormComponent } from './languageform.component';
  import { PatentFormComponent } from './patentform.component';
  import { PublicationFormComponent } from './publicationform.component';
  import {DataListModule} from 'primeng/datalist';
  import {SidebarModule} from 'primeng/sidebar';
  import {SlideMenuModule} from 'primeng/slidemenu';
  import {MenuItem} from 'primeng/api';
  import { CalendarModule } from 'primeng/calendar';
  import { FormsModule } from '@angular/forms';
  import {RadioButtonModule} from 'primeng/radiobutton';
  import {InputTextModule} from 'primeng/inputtext';
  import {DropdownModule} from 'primeng/dropdown';
  import {KeyFilterModule} from 'primeng/keyfilter';
  import {AutoCompleteModule} from 'primeng/autocomplete';
  import {TableModule} from 'primeng/table';
  import {PanelModule} from 'primeng/panel';
  import {ButtonModule} from 'primeng/button';
  import {CheckboxModule} from 'primeng/checkbox';
  import {SliderModule} from 'primeng/slider';
  import {InputMaskModule} from 'primeng/inputmask';
  import {InputTextareaModule} from 'primeng/inputtextarea';
  import {ChipsModule} from 'primeng/chips';
  import { HonorawardComponent } from '../person/honoraward.component';
  import {CodeHighlighterModule} from 'primeng/codehighlighter';
  
  
  
  @NgModule({
    imports: [CommonModule,FormsModule,FormRoutingModule,CodeHighlighterModule,PanelModule,ChipsModule,InputTextareaModule,SliderModule,InputMaskModule,CheckboxModule,ButtonModule,TableModule,KeyFilterModule,AutoCompleteModule,DropdownModule,RadioButtonModule,TabViewModule,InputTextModule,DataListModule,CardModule,SidebarModule,SlideMenuModule,CalendarModule],
    declarations: [FormComponent,DemographicFormComponent,ContactFormComponent,PatentFormComponent,PublicationFormComponent,LanguageFormComponent,HonorAwardFormComponent,CertificationFormComponent,CourseFormComponent,EducationFormComponent,VoluenteeringExpformFormComponent,SkillActivityFormComponent,EmployerDetailFormComponent,ProjectFormComponent],
    exports: [FormComponent]
  })
  export class FormModule { }
  </code></pre>
  
  <p>form.component.html</p>
  
  <pre><code>&lt;sd-contactform&gt;&lt;/sd-contactform&gt;
  </code></pre>
  
  <p>contry.json</p>
  
  <pre><code>[
  {"country" : "Afghanistan"},
  {"country" : "Albania"},
  {"country" : "Algeria"},
  {"country" : "American Samoa"},
  {"country" : "Andorra"},
  {"country" : "Angola"},
  {"country" : "Anguilla"},
  {"country" : "Antarctica"},
  {"country" : "Antigua and Barbuda"},
  {"country" : "Argentina"},
  {"country" : "Armenia"},
  {"country" : "Aruba"},
  {"country" : "Australia"},
  {"country" : "Austria"},
  {"country" : "Azerbaijan"},
  {"country" : "Bahamas"},
  {"country" : "Bahrain"},
  {"country" : "Bangladesh"},
  {"country" : "Barbados"},
  {"country" : "Belarus"},
  {"country" : "Belgium"},
  {"country" : "Belize"},
  {"country" : "Benin"},
  {"country" : "Bermuda"},
  {"country" : "Bhutan"},
  {"country" : "Bolivia"},
  {"country" : "Bosnia and Herzegovina"},
  {"country" : "Botswana"},
  {"country" : "Bouvet Island"},
  {"country" : "Brazil"},
  {"country" : "British Indian Ocean Territory"},
  {"country" : "Brunei"},
  {"country" : "Bulgaria"},
  {"country" : "Burkina Faso"},
  {"country" : "Burundi"},
  {"country" : "Cambodia"},
  {"country" : "Cameroon"},
  {"country" : "Canada"},
  {"country" : "Cape Verde"},
  {"country" : "Cayman Islands"},
  {"country" : "Central African Republic"},
  {"country" : "Chad"},
  {"country" : "Chile"},
  {"country" : "China"},
  {"country" : "Christmas Island"},
  {"country" : "Cocos (Keeling) Islands"},
  {"country" : "Colombia"},
  {"country" : "Comoros"},
  {"country" : "Congo"},
  {"country" : "The Democratic Republic of Congo"},
  {"country" : "Cook Islands"},
  {"country" : "Costa Rica"},
  {"country" : "Ivory Coast"},
  {"country" : "Croatia"},
  {"country" : "Cuba"},
  {"country" : "Cyprus"},
  {"country" : "Czech Republic"},
  {"country" : "Denmark"},
  {"country" : "Djibouti"},
  {"country" : "Dominica"},
  {"country" : "Dominican Republic"},
  {"country" : "East Timor"},
  {"country" : "Ecuador"},
  {"country" : "Egypt"},
  {"country" : "England"},
  {"country" : "El Salvador"},
  {"country" : "Equatorial Guinea"},
  {"country" : "Eritrea"},
  {"country" : "Estonia"},
  {"country" : "Ethiopia"},
  {"country" : "Falkland Islands"},
  {"country" : "Faroe Islands"},
  {"country" : "Fiji Islands"},
  {"country" : "Finland"},
  {"country" : "France"},
  {"country" : "French Guiana"},
  {"country" : "French Polynesia"},
  {"country" : "French Southern territories"},
  {"country" : "Gabon"},
  {"country" : "Gambia"},
  {"country" : "Georgia"},
  {"country" : "Germany"},
  {"country" : "Ghana"},
  {"country" : "Gibraltar"},
  {"country" : "Greece"},
  {"country" : "Greenland"},
  {"country" : "Grenada"},
  {"country" : "Guadeloupe"},
  {"country" : "Guam"},
  {"country" : "Guatemala"},
  {"country" : "Guinea"},
  {"country" : "Guinea-Bissau"},
  {"country" : "Guyana"},
  {"country" : "Haiti"},
  {"country" : "Heard Island and McDonald Islands"},
  {"country" : "Holy See (Vatican City State)"},
  {"country" : "Honduras"},
  {"country" : "Hong Kong"},
  {"country" : "Hungary"},
  {"country" : "Iceland"},
  {"country" : "India"},
  {"country" : "Indonesia"},
  {"country" : "Iran"},
  {"country" : "Iraq"},
  {"country" : "Ireland"},
  {"country" : "Israel"},
  {"country" : "Italy"},
  {"country" : "Jamaica"},
  {"country" : "Japan"},
  {"country" : "Jordan"},
  {"country" : "Kazakstan"},
  {"country" : "Kenya"},
  {"country" : "Kiribati"},
  {"country" : "Kuwait"},
  {"country" : "Kyrgyzstan"},
  {"country" : "Laos"},
  {"country" : "Latvia"},
  {"country" : "Lebanon"},
  {"country" : "Lesotho"},
  {"country" : "Liberia"},
  {"country" : "Libyan Arab Jamahiriya"},
  {"country" : "Liechtenstein"},
  {"country" : "Lithuania"},
  {"country" : "Luxembourg"},
  {"country" : "Macao"},
  {"country" : "Macedonia"},
  {"country" : "Madagascar"},
  {"country" : "Malawi"},
  {"country" : "Malaysia"},
  {"country" : "Maldives"},
  {"country" : "Mali"},
  {"country" : "Malta"},
  {"country" : "Marshall Islands"},
  {"country" : "Martinique"},
  {"country" : "Mauritania"},
  {"country" : "Mauritius"},
  {"country" : "Mayotte"},
  {"country" : "Mexico"},
  {"country" : "Micronesia, Federated States of"},
  {"country" : "Moldova"},
  {"country" : "Monaco"},
  {"country" : "Mongolia"},
  {"country" : "Montserrat"},
  {"country" : "Morocco"},
  {"country" : "Mozambique"},
  {"country" : "Myanmar"},
  {"country" : "Namibia"},
  {"country" : "Nauru"},
  {"country" : "Nepal"},
  {"country" : "Netherlands"},
  {"country" : "Netherlands Antilles"},
  {"country" : "New Caledonia"},
  {"country" : "New Zealand"},
  {"country" : "Nicaragua"},
  {"country" : "Niger"},
  {"country" : "Nigeria"},
  {"country" : "Niue"},
  {"country" : "Norfolk Island"},
  {"country" : "North Korea"},
  {"country" : "Northern Ireland"},
  {"country" : "Northern Mariana Islands"},
  {"country" : "Norway"},
  {"country" : "Oman"},
  {"country" : "Pakistan"},
  {"country" : "Palau"},
  {"country" : "Palestine"},
  {"country" : "Panama"},
  {"country" : "Papua New Guinea"},
  {"country" : "Paraguay"},
  {"country" : "Peru"},
  {"country" : "Philippines"},
  {"country" : "Pitcairn"},
  {"country" : "Poland"},
  {"country" : "Portugal"},
  {"country" : "Puerto Rico"},
  {"country" : "Qatar"},
  {"country" : "Reunion"},
  {"country" : "Romania"},
  {"country" : "Russian Federation"},
  {"country" : "Rwanda"},
  {"country" : "Saint Helena"},
  {"country" : "Saint Kitts and Nevis"},
  {"country" : "Saint Lucia"},
  {"country" : "Saint Pierre and Miquelon"},
  {"country" : "Saint Vincent and the Grenadines"},
  {"country" : "Samoa"},
  {"country" : "San Marino"},
  {"country" : "Sao Tome and Principe"},
  {"country" : "Saudi Arabia"},
  {"country" : "Scotland"},
  {"country" : "Senegal"},
  {"country" : "Seychelles"},
  {"country" : "Sierra Leone"},
  {"country" : "Singapore"},
  {"country" : "Slovakia"},
  {"country" : "Slovenia"},
  {"country" : "Solomon Islands"},
  {"country" : "Somalia"},
  {"country" : "South Africa"},
  {"country" : "South Georgia and the South Sandwich Islands"},
  {"country" : "South Korea"},
  {"country" : "South Sudan"},
  {"country" : "Spain"},
  {"country" : "SriLanka"},
  {"country" : "Sudan"},
  {"country" : "Suriname"},
  {"country" : "Svalbard and Jan Mayen"},
  {"country" : "Swaziland"},
  {"country" : "Sweden"},
  {"country" : "Switzerland"},
  {"country" : "Syria"},
  {"country" : "Tajikistan"},
  {"country" : "Tanzania"},
  {"country" : "Thailand"},
  {"country" : "Togo"},
  {"country" : "Tokelau"},
  {"country" : "Tonga"},
  {"country" : "Trinidad and Tobago"},
  {"country" : "Tunisia"},
  {"country" : "Turkey"},
  {"country" : "Turkmenistan"},
  {"country" : "Turks and Caicos Islands"},
  {"country" : "Tuvalu"},
  {"country" : "Uganda"},
  {"country" : "Ukraine"},
  {"country" : "United Arab Emirates"},
  {"country" : "United Kingdom"},
  {"country" : "United States"},
  {"country" : "United States Minor Outlying Islands"},
  {"country" : "Uruguay"},
  {"country" : "Uzbekistan"},
  {"country" : "Vanuatu"},
  {"country" : "Venezuela"},
  {"country" : "Vietnam"},
  {"country" : "Virgin Islands, British"},
  {"country" : "Virgin Islands, U.S."},
  {"country" : "Wales"},
  {"country" : "Wallis and Futuna"},
  {"country" : "Western Sahara"},
  {"country" : "Yemen"},
  {"country" : "Yugoslavia"},
  {"country" : "Zambia"},
  {"country" : "Zimbabwe"}
  ]
  </code></pre>