小编Jam*_*hed的帖子

使用 --stats-json 构建 Angular 6 不生成 stats.json 文件

我正在尝试为我的 Angular 6 应用程序生成 stats.json 文件。下面的事情我已经尝试过了,但根本没有生成文件。我的系统需要在每个 angular cli 命令之前运行“npm run”

  1. 我已经运行了"npm run ng build --prod --stats-json"以及"npm run ng build --prod --stats-json=true"

  2. 我已经运行了“npm run ng build --stats-json”以及“npm run ng build --stats-json=true”(没有构建命令)。

  3. 通过参考 cli 文档使用“npm run ng build --statsJson=true”

但是仍然没有生成 stats.json 文件,我想使用 webpack 包分析器读取该文件。欢迎在这方面提供任何帮助、建议或更正。

下面是我的 package.json 中的脚本。

“脚本”:{

"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"gulp": "gulp",
"bundle-report": "webpack-bundle-analyzer dist/stats.json", …
Run Code Online (Sandbox Code Playgroud)

npm webpack angular webpack-bundle-analyzer

5
推荐指数
2
解决办法
6616
查看次数

无法访问组件中的服务变量 - Angular2

我正在服务中进行 HTTP 调用并将返回数据分配给服务变量。现在,当我尝试访问组件中的服务变量时,它在控制台中记录为未定义。但是,当我将日志代码放入服务本身时它会被记录,但在组件中它不起作用。

下面是我的代码供参考:

英雄服务

import { Injectable }              from '@angular/core';
import { Http, Response }          from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { Hero } from './hero';

@Injectable()
export class HeroService {
heroes: Hero[];
hero: Hero;
gbl: Hero[];

  private heroesUrl = 'SERVICE URL';
  constructor (private http: Http) {}

  getHeroes(): Observable<Hero[]> {
    return this.http.get(this.heroesUrl)
                    .map(this.extractData)
                    .catch(this.handleError);
  }
  private extractData(res: Response) {
    let body = res.json()['data'];
    this.gbl = body;
    return body || { };

  } …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-routing angular2-services angular2-observables angular

2
推荐指数
1
解决办法
4906
查看次数