带有标志和国家代码的 Angular 2 下拉菜单

标签 angular drop-down-menu internationalization countries

我的应用程序是通过 ng2 翻译进行国际化的,在我的登录页面中,我想要一个类似下拉菜单的东西,其中每个选项都有国旗和国家名称,是否可以安装一些东西来快速解决这个问题? 或者也许有任何可以帮助我自己做的例子

最佳答案

我需要类似的功能。

为此,我创建了 ngx-flag-picker图书馆。

How to use

Add a link tag with flag-icon-css library to your index.html file.

Add NgxFlagPickerModule to your module in the import section.

After:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <ngx-flag-picker
      [selectedCountryCode]="selectedCountryCode"
      [countryCodes]="countryCodes"
      (changedCountryCode)="changeSelectedCountryCode($event)">
    </ngx-flag-picker>
    <h1>{{ selectedCountryCode }}</h1>
  `
})
export class AppComponent {
  selectedCountryCode = 'us';
  countryCodes = ['us', 'lu', 'de', 'bs', 'br', 'pt'];

  changeSelectedCountryCode(value: string): void {
    this.selectedCountryCode = value;
  }
}

链接:

关于带有标志和国家代码的 Angular 2 下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498529/

相关文章:

内部带有 HTML 标记的 Angular 2 i18n 消息

javascript - 如何在表单验证时在 Angular 模板中显示 <span> 元素?

Angular 2 : Custom validation for file extensions

angular - 如何为 Angular 中的输入变化编写测试用例

jquery - jQuery jqGrid 的自定义下拉格式化程序

ruby-on-rails - Ruby on Rails 在测试(flash 消息和 View )和 I18N 方面的最佳实践

java - Spring MessageSource 通过多个语言环境查找

javascript - 从服务获取数据后如何刷新数据表内联编辑器?

html - checkin Microsoft Edge 时下拉菜单出现问题

javascript - Bootstrap 4 : Is there a way to nest a bootstrap "btn-toolbar" in order to make it x-axis scrollable on smaller screens?