akveo / akveo/nebular

NbDatepickerComponent missing dependency injection with optimization enabled

Ouverte
#2,553 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
8.1k
Forks
1.5k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

### Issue type

**I'm submitting a ...** (check one with "x")

* [x] bug report
* [ ] feature request

### Issue description

**Current behavior:**
When `optimization` is enabled in `angular.json`, any page with an NbDatepickerDirective directive breaks with the following console error:
```
ERROR TypeError: Cannot read property 'trigger' of undefined
at NbDatepickerComponent.createTriggerStrategy (index.js:20384)
at NbDatepickerComponent.subscribeOnTriggers (index.js:20390)
at NbDatepickerComponent.attach (index.js:20330)
at NbDatepickerDirective_1.setupPicker (index.js:20097)
at NbDatepickerDirective_1.set setPicker [as setPicker] (index.js:19991)
at updateProp (core.js:32189)
at core.js:31867
at core.js:44367
at checkAndUpdateNode (core.js:44306)
at debugCheckAndUpdateNode (core.js:45328)
```
Debugging the code, it turns out that all of the arguments to the `NbBasePicker` constructor are undefined, including the `triggerStrategyBuilder` argument, which causes the error presented above.

**Expected behavior:**
The page does not break and the date picker works as expected, which is what happens when `optimization` is disabled.

**Steps to reproduce:**
Run `ng serve` with an Angular 8 build configuration set up to enable `optimization`, an app module importing `NbDatepickerModule.forRoot()`, a component module importing `NbDatepickerModule`, and a component with a template including the Related code section below.

**Related code:**
```

```

**Workaround:**
Noting that `NbSelectComponent` worked and the only difference with `NbDatepickerComponent` was that it did not have dependency injection, I was able to solve this issue by manually updating `node_modules/@nebular/theme/fesm2015/index.js:20553`. Presumably, the expectation is that the dependency injection is inherited from `NbBasePicker`, which happens to not be the case with `optimization` enabled.
```diff
NbDatepickerComponent = __decorate$144([
Component({
selector: 'nb-datepicker',
template: ''
- })
+ }),
+ __param$24(0, Inject(NB_DOCUMENT)),
+ __param$24(6, Optional()), __param$24(6, Inject(NB_DATE_SERVICE_OPTIONS)),
+ __metadata$96("design:paramtypes", [Object, NbPositionBuilderService,
+ NbTriggerStrategyBuilderService,
+ NbOverlayService,
+ ComponentFactoryResolver,
+ NbDateService, Object])
```

### Other information:

**npm, node, OS, Browser**
Node, npm: v10.13.0, 6.14.1
OS: Windows 10
Browser: Chrome

**Angular, Nebular**
Angular: 8.2.14
Nebular: 4.1.2

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.