«Нет поставщика для ViewContainerRef» при использовании компонента ng-packagr - PullRequest
0 голосов
/ 18 декабря 2018

Я создал компоненты библиотека с использованием углового клика ng generate library, с компонентом, который использует *ngIf внутри модуля.

После успешной сборки иустановить библиотеку в моем основном проекте, когда я пытаюсь использовать компонент, я получаю ошибку No provider for ViewContainerRef.

Версии:

@ angular / cli версия: "~ 7.0.6",

@ angular / * версия: "~ 7.0.0"

Ошибка:

Ошибка ОШИБКИ: StaticInjectorError (AppModule) [NgIf -> ViewContainerRef]: StaticInjectorError(Платформа: ядро) [NgIf -> ViewContainerRef]: NullInjectorError: Нет поставщика для ViewContainerRef!

компонент:

import {Component, OnInit, Input} from '@angular/core';

@Component({
  selector: 'al-card',
  templateUrl: './card.component.html',
  styleUrls: ['./card.component.scss']
})
export class CardComponent implements OnInit {

  @Input() header: string;
  @Input() text: string;

  constructor() { }

  ngOnInit() {
  }

}

шаблон:

<div *ngIf="header">

</div>

модуль:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CardComponent } from './card.component';

@NgModule({
  declarations: [CardComponent],
  imports: [
    CommonModule
  ],
  exports: [CardComponent],
})
export class CardModule { }

1 Ответ

0 голосов
/ 18 декабря 2018

Я обнаружил проблему, она была решена путем добавления "preserveSymlinks": true в файл angular.json моего основного проекта.

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "preserveSymlinks": true,
             ...

Здесь я нашел решение: https://github.com/angular/angular-cli/issues/10896

...