5

In an angular cli project, I managed to embed json like this

  • add to typings.d.ts
declare module "*.json" {
    const value: any;
    export default value;
}
  • import .json
import * as data from '../assets/data.json';

But if I want to compile this into an Angular 5 module with ng-packagr, I get the following error:

Error at .../.ng_pkg_build/my-module/ts/src/app/my-module.module. ts:28:33: Cannot find module '../assets/data.json'.

Did anyone encountered this issue and knows how to solve it?

Adrian Ber
  • 20,474
  • 12
  • 67
  • 117

1 Answers1

0

Ng-packagr in version 4.4.0 finally added support for resolveJsonModule. See a thread with this issue.

import { Component, Input } from '@angular/core';
import jsonData from './angular.component.json';

@Component({
  selector: 'ng-component',
  template: '<h1>{{title}}</h1>{{data}}',
  styleUrls: ['./angular.component.scss']
})
export class AngularComponent {
  @Input()
  title = 'Angular';

  data = jsonData;
}
ssuperczynski
  • 3,190
  • 3
  • 44
  • 61