Git Product home page Git Product logo

Comments (13)

guillaume-ro-fr avatar guillaume-ro-fr commented on July 24, 2024 3

Thanks @tanjunior for your post, maybe I will add a .forChild() function (Angular doc).

from ngx-country-picker.

guillaume-ro-fr avatar guillaume-ro-fr commented on July 24, 2024 2

Hi @netcraft-devops,

I created a demo repository with Ionic : https://github.com/guillaume-ro-fr/ionic-country-picker-demo

As you can see, Ionic works with the configuration, you just need to copy the countries.json file and the data folder to the src/assets folder from node_modules/world_countries because Ionic does not allow a configuration for copying assets on compilation.

Tell if it's work for you with my configuration !

from ngx-country-picker.

tanjunior avatar tanjunior commented on July 24, 2024 1

There is a module for each page because i am doing lazy loading.
https://www.joshmorony.com/what-does-lazy-loading-do-in-ionic/

from ngx-country-picker.

guillaume-ro-fr avatar guillaume-ro-fr commented on July 24, 2024 1

@tanjunior You just need to import the module in the NgModule that will be using country-picker.

from ngx-country-picker.

tanjunior avatar tanjunior commented on July 24, 2024 1

@guillaume-ro-fr It works 👍
By the way, does [(ngModel)] not work within country picker? example:<country-picker [(ngModel)]="user.country"></country-picker>

from ngx-country-picker.

guillaume-ro-fr avatar guillaume-ro-fr commented on July 24, 2024

Hi @netcraft-devops, sorry for the delay 😅
Can you post your AppModule file please ?
I don't use it with Ionic but I don't think it's a problem

from ngx-country-picker.

netcraft-devops avatar netcraft-devops commented on July 24, 2024

@guillaume-ro-fr , so sorry for the delay in posting my AppModule

Here it is:

import { ErrorHandler, NgModule } from '@angular/core';
import { HttpModule, Http } from '@angular/http';
import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http";
import { BrowserModule } from '@angular/platform-browser';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { IonicStorageModule, Storage } from '@ionic/storage';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { CustomConfig, Ng2UiAuthModule } from 'ng2-ui-auth';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { CountryPickerModule } from 'ngx-country-picker';

import { Signals } from '../providers/providers';
import { Settings } from '../providers/providers';
import { User } from '../providers/providers';
import { Api } from '../providers/providers';
import { ApiHttpInterceptor } from '../providers/providers';
import { CONFIG } from '../config';

import { MainApp } from './app.component';

// The translate loader needs to know where to load i18n files
// in Ionic's static asset pipeline.
export function HttpLoaderFactory(http: Http) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

export class AppAuthConfig extends CustomConfig {
  defaultHeaders = {'Content-Type': 'application/json'};
  httpInterceptor = function() { return true; };
  providers = {
    google: { clientId: CONFIG.GOOGLE_CLIENT_ID },
    facebook: { clientId: CONFIG.FACEBOOK_KEY }
  };
  withCredentials = false;
  tokenRoot = null;
  tokenName = 'token';
  tokenPrefix = 'satellizer';
  authHeader = 'Authorization';
  authToken = 'Bearer';
  storageType: 'localStorage';
  baseUrl = CONFIG.API_ENDPOINT;
}

export function provideSettings(storage: Storage) {
  /**
   * The Settings provider takes a set of default settings for your app.
   *
   * You can add new settings options at any time. Once the settings are saved,
   * these values will not overwrite the saved values (this can be done manually if desired).
   */
  return new Settings(storage, {
    subscribed: false,
    paused_subscription: false,
    name: '',
    email: '',
    subscription_id: '',
    subscription_amount: '',
  });
}

@NgModule({
  declarations: [
    MainApp
  ],
  imports: [
    BrowserModule,
    HttpModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [Http]
      }
    }),
    IonicModule.forRoot(MainApp),
    IonicStorageModule.forRoot(),
    Ng2UiAuthModule.forRoot(AppAuthConfig),
    CountryPickerModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MainApp
  ],
  providers: [
    Api,
    Signals,
    User,
    SplashScreen,
    StatusBar,
    InAppBrowser,
    { provide: Settings, useFactory: provideSettings, deps: [Storage] },
    { provide: HTTP_INTERCEPTORS, useClass: ApiHttpInterceptor, multi: true },
    // Keep this to enable Ionic's runtime error handling during development
    { provide: ErrorHandler, useClass: IonicErrorHandler }
  ]
})
export class AppModule { }

from ngx-country-picker.

tanjunior avatar tanjunior commented on July 24, 2024

having this error too.

Template parse errors:
'country-picker' is not a known element:
1. If 'country-picker' is an Angular component, then verify that it is part of this module.
2. If 'country-picker' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 
("
     [ERROR ->]<country-picker></country-picker>
")

I took a look at your demo repo. I am pretty much doing the same things but strangely I'm getting the error. my repo

from ngx-country-picker.

guillaume-ro-fr avatar guillaume-ro-fr commented on July 24, 2024

Hi @tanjunior and @netcraft-devops !

I found the error in your repo : you have a module by page. I don't think it's a good idea to create a new module for each page, but I didn't find any documentation on this, except the --no-module option on Ionic CLI. And I didn't program mobile apps so ...

To solve your problem, you need to import the module on each NgModule and remove the importation on AppModule, like this :

import { CountryPickerModule } from 'ngx-country-picker';

@NgModule({
  declarations: [
    EditProfilePage,
  ],
  imports: [
    IonicPageModule.forChild(EditProfilePage),
    CountryPickerModule.forRoot(),
  ],
})
export class EditProfilePageModule {}

from ngx-country-picker.

tanjunior avatar tanjunior commented on July 24, 2024

Thanks @tanjunior for your post, maybe I will add a .forChild() function (Angular doc).

Looking forward to that.

To solve your problem, you need to import the module on each NgModule and remove the importation on AppModule, like this

Meanwhile I will try this workaround and get back to you. Just to make sure.. I have to import them on each NgModule or just the pages that will be using country-picker?

from ngx-country-picker.

tanjunior avatar tanjunior commented on July 24, 2024

I found a way to make use of CountryPickerService and populate it to <ion-option> nested within <ion-select>

In page.ts we retrieve all available country and store in to a variable.

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireDatabase } from 'angularfire2/database';
import firebase from 'firebase';
import { CountryPickerService, ICountry } from 'ngx-country-picker';

@IonicPage()
@Component({
  selector: 'page-edit-profile',
  templateUrl: 'edit-profile.html',
})
export class EditProfilePage {
  user = this.navParams.get("user");
  uid = this.navParams.get("uid");
  countries: ICountry[] = [];

  constructor(public navCtrl: NavController, public navParams: NavParams, public db: AngularFireDatabase, public cPickService: CountryPickerService) {
    this.cPickService.getCountries().subscribe((countries: ICountry[]) => //get all country
      this.countries = countries);  // store it in countries
  }

  saveProfile() {
    this.db.list(`users`).update(this.uid, this.user).then(() =>{
      this.navCtrl.pop();
    });
  }

}

In page.html from the previous variable we use *ngFor to populate the options.

<ion-item>
  <ion-label floating>Country</ion-label>
  <ion-select [(ngModel)]="user.country">
    <ion-option *ngFor="let country of countries" [value]="country.name.common">{{ country.name.common }}</ion-option>
  </ion-select>
</ion-item>

from ngx-country-picker.

CedrickTAGNE avatar CedrickTAGNE commented on July 24, 2024

Please I have a problem when using ngx-country-picker. the component is empty.

country.json not found

from ngx-country-picker.

gmehta9 avatar gmehta9 commented on July 24, 2024

country.json not found

from ngx-country-picker.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.