标签: ng-bootstrap

从Json中提取ng-bootstrap typeahead的数据

尝试制作Play Framework(REST)并ng-bootstrap - Typeahead一起工作.但我面临从json响应中提取数据的问题.例如我写"test"(在数据库中搜索name),服务器返回json数组(一切都正确):

[{
  "id": 1,
  "name": "test",
  "annotation": "test annotation",
  "kiMin": 1,
  "kiMax": 2,
  "cosFiMin": 3,
  "cosFiMax": 4
}, {
  "id": 4,
  "name": "test2",
  "annotation": "test annotation",
  "kiMin": 1,
  "kiMax": 2,
  "cosFiMin": 3,
  "cosFiMax": 4
}]
Run Code Online (Sandbox Code Playgroud)

但视图看起来像这样:

在此输入图像描述

这是我的代码:

http.service.ts

import { Injectable }     from '@angular/core';
import { Http, Response } from '@angular/http';
import { Equipment }           from './equipment';
import { Observable }     from 'rxjs/Observable';
@Injectable()
export class HttpService {
  private Url = …
Run Code Online (Sandbox Code Playgroud)

json ng-bootstrap angular

7
推荐指数
1
解决办法
5684
查看次数

始终需要用于反应形式的Angular 4 DatePicker的ngBootstrap

使用反应形式我添加了ngbDatePicker:

<input type="text"
        id="business_incorp_date"
        class="form-control"
        formControlName="business_incorp_date"
        ngbDatepicker
        #incorporatedDatePicker="ngbDatepicker"
        (click)="incorporatedDatePicker.toggle()"
        readonly>
Run Code Online (Sandbox Code Playgroud)

对于以下形式的表单模型:

this.form = this.formBuilder.group({
  id: [
    0, [Validators.required]
  ],

  // ... removed for brevity

  business_type: [
    '', [Validators.required]
  ],
  business_incorp_date: [
    '', [FormValidators.date] // <-- NOT REQUIRED BY MODEL
  ],
  business_desc: [
    '', [Validators.required]
  ]

  // ...
});
Run Code Online (Sandbox Code Playgroud)

但是,如果该字段为空,则对于以下内容仍然是ngInvalid ngbDateFormat:

{ "ngbDate": { "invalid": { "year": null, "month": null, "day": null } } }
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何使DatePicker字段允许空字符串?

datepicker ng-bootstrap angular

7
推荐指数
1
解决办法
7150
查看次数

Angular 2:NgbModal在视野中转换

假设我有这样的模态模板:

<div class="modal-header">
  <h3 [innerHtml]="header"></h3>
</div>

<div class="modal-body">
  <ng-content></ng-content>
</div>

<div class="modal-footer">
</div>
Run Code Online (Sandbox Code Playgroud)

我从另一个组件调用这个模态,所以:


    const modalRef = this.modalService.open(MobileDropdownModalComponent, {
      keyboard: false,
      backdrop: 'static'
    });

    modalRef.componentInstance.header = this.text;
Run Code Online (Sandbox Code Playgroud)

我怎么能用NgbModal绑定等放入html?成ng-content

javascript typescript ng-bootstrap ng-modal angular

7
推荐指数
1
解决办法
765
查看次数

Angular中的Mock NgbModal

我需要模拟NgbModal以角度进行一些单元测试,但我不知道如何做到这一点.这是我的功能:

    openModal(deviceID: string, productID: string){
        const modalRef =  this.modalService.open(ProductModal)
        modalRef.componentInstance.content = {
            deviceId: deviceID,
            productId: productID
        } 
        modalRef.componentInstance.toEmit.subscribe(($e) => {
            if ($e === true) this.reloadList();
        });
    }
Run Code Online (Sandbox Code Playgroud)

我应该做些什么?

unit-testing jasmine ng-bootstrap ng-modal angular

7
推荐指数
1
解决办法
3374
查看次数

折叠无法在ng-bootstrap和angular 4应用程序中使用navbar breadcrumb按钮

我正在为我的应用程序使用角度4和bootstrap 4 beta 2和ng-bootstrap,并使用ng-bootstrap.

我已经从bootstrap文档示例中添加了导航栏.

代码如下所示:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
    <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
Run Code Online (Sandbox Code Playgroud)

我还在angular-cli.json中添加了bootstrap样式.该代码如下所示:

 "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css", …
Run Code Online (Sandbox Code Playgroud)

collapse bootstrap-4 ng-bootstrap twitter-bootstrap-4-beta

7
推荐指数
2
解决办法
2万
查看次数

角度2/4。我可以将函数绑定到 ngModel 吗?

我正在使用 ng-bootstrap 中的 ngbDatePicker。我正在尝试设置从 API 返回的默认日期。这似乎不起作用,因为我收到错误或浏览器冻结。代码片段看起来像这样

<input class="form-control" placeholder="dd-mm-yyyy" name="from" [ngModel]="formatDate(filter.nodes[0])" (ngModelChange)="filter.nodes[0] = updateDate($event)" ngbDatepicker #d1="ngbDatepicker">

filter.nodes[0] 是从 API 以字符串形式返回的日期值。我需要将其格式化为 JS 对象,以便将其绑定到输入。

javascript ng-bootstrap angular

7
推荐指数
2
解决办法
2万
查看次数

替代/深/

我想更改ng bootstrap分页组件的样式并使用/deep/Angular 6应用程序中的链接.以下代码工作正常,但控制台显示警告,代码已被弃用.

那么,我应该如何更改它以摆脱警告?

这是我目前使用的CSS代码:

ngb-pagination /deep/ .page-item.disabled .page-link{
    background: none;
  }

 ngb-pagination /deep/ .page-item.active .page-link {
    background-color: #223C61;
    &:focus, &:visited{
      outline: none;
      box-shadow: none;
    }
  }
Run Code Online (Sandbox Code Playgroud)

css ng-bootstrap angular angular6

7
推荐指数
2
解决办法
7712
查看次数

日期选择器的国际化

我尝试强制 jHipster 生成的 Angular 5 项目中的日期选择器使用波兰语语言环境,一周和几个月。据我了解有关文档:

https://ng-bootstrap.github.io/#/components/datepicker/examples#i18n

它应该使用默认设置,即:

共享-common.module.ts

...
import { registerLocaleData } from '@angular/common';
import locale from '@angular/common/locales/pl';
...

providers: [
    ...
    {
        provide: LOCALE_ID,
        useValue: 'pl'
    },
],
...
export class TestSharedCommonModule {
    constructor() {
        registerLocaleData(locale);
    }
}
Run Code Online (Sandbox Code Playgroud)

用法

<input id="field_testDate" type="text" class="form-control" name="testDate" 
ngbDatepicker  #testDateDp="ngbDatepicker" [(ngModel)]="tester.testDate"
            required/>
Run Code Online (Sandbox Code Playgroud)

不幸的是它不起作用,我也尝试了不同的方法,例如:

https://angular.io/api/core/LOCALE_ID

或者

https://github.com/NativeScript/nativescript-angular/issues/1147 - 我在这里复制了语言环境文件

你有什么想法可能是错的吗?

更新

我最终是这样解决的:

日期选择器-i18n.ts

import { Inject, Injectable, LOCALE_ID } from '@angular/core';
import { NgbDatepickerI18n } from '@ng-bootstrap/ng-bootstrap';

const I18N_VALUES = {
    en: …
Run Code Online (Sandbox Code Playgroud)

localization datepicker ng-bootstrap angular angular5

6
推荐指数
1
解决办法
3165
查看次数

使用 ReactiveForms 和 NgbModal 时的 ExpressionChangedAfterItHasBeenCheckedError

我有一个反应式表单,当用户在输入中按下 ESC 键时,我想在表单隐藏之前显示一个“你确定”模式。
一旦显示模态,我就会在控制台中收到以下异常:

ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has 
changed after it was checked. Previous value: 'ng-untouched: true'. Current 
value: 'ng-untouched: false'.
Run Code Online (Sandbox Code Playgroud)

这是一个显示问题的 stackblitz(焦点输入并按 ESC)

注意:当您聚焦输入,模糊并再次聚焦时,问题不会再次出现ng-untouched变化。

有什么解决方法吗?实现此类功能的推荐方法是什么?

提前致谢!

ng-bootstrap angular angular-reactive-forms

6
推荐指数
1
解决办法
2950
查看次数

如何从星期日而不是星期一在 ng bootstrap Datepicker 中开始日历周?

我想将 ngbDatepicker 设置为从星期日开始一周,而不是默认的星期一。

我正在尝试使用weekStartsOn="0"但它没有效果。这是我的 html 代码

<input ngbDatepicker #d="ngbDatepicker" class="form-control" [minDate]="minDate" [maxDate]="maxDate" [markDisabled]="isDisabled" weekStartsOn="0">

ng-bootstrap angular ngb-datepicker

6
推荐指数
1
解决办法
1927
查看次数