问题
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?
回答1:
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;
}
来源:https://stackoverflow.com/questions/48240081/embed-json-in-ng-packagr