标签: angular-cli

angular2 - 使用angular-cli的bootstrap-sass编译错误

我使用angular-cli:1.0.0-beta.19-3 with node:v5.11.1

在我的angular-cli.json文件中,我已将全局样式文件扩展名设置为.scss.

这是我的样式文件.

angular2/SRC/styles.scss

// Default Font
@import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600);

// Typography
$font-family-sans-serif: "Raleway", sans-serif;
$font-size-base: 14px;
$line-height-base: 1.6;
$text-color: #636b6f;

// Import bootstrap
@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
Run Code Online (Sandbox Code Playgroud)

当我尝试导入bootrap-sass模块时,错误会吐出,它会给出与glyphicon图标相关的错误.不知道如何解决它.

ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss
Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.eot' in '/var/www/angular/src'
 @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4253-4315 6:4338-4400
 @ ./src/styles.scss
 @ multi styles

ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss
Module not found: Error: Can't resolve '../fonts/bootstrap/glyphicons-halflings-regular.woff2' in '/var/www/angular2/src'
 @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss 6:4452-4516
 @ ./src/styles.scss
 @ multi styles

ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/styles.scss
Module not found: Error: Can't …
Run Code Online (Sandbox Code Playgroud)

bootstrap-sass angular-cli angular

8
推荐指数
1
解决办法
3780
查看次数

找不到模块@angular \ cli \ bin \ ng

我在安装anngular-cli时遇到了麻烦,因为它无法识别git bash中的ng命令,但可以在Windows 7的cmd中使用。

我在网上寻找了一些问题,但没有真正找到解决方案。

在这里,错误:

   ng -v
   module.js:549
    throw err;
    ^

   Error: Cannot find module 'C:\Program 
   Files\Git\node_modules\@angular\cli\bin\ng'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
Run Code Online (Sandbox Code Playgroud)

在全局安装Node和angular-cli之后,我第一次使用ng发生此错误。

在Windowsd 10上的笔记本电脑上工作时,没有出现此错误。

谢谢,

node.js angular-cli

8
推荐指数
5
解决办法
1万
查看次数

ng-build上的端口和代理配置

我有一个前端在int.myapp.com上运行,它是在int.backend.myapp.com上的后端.我以为我可以像这样使用proxy.config.json进行代理:

 "/api": {
    "target": "https://int.backend.myapp.com",
    "secure": true,
    "changeOrigin": true
  }
Run Code Online (Sandbox Code Playgroud)

在我的package.json文件中

"start": "ng serve --proxy-config proxy.conf.json"
Run Code Online (Sandbox Code Playgroud)

一切都适用于我的开发环境.

但是当我为生产而建立:

ng buil --prod
Run Code Online (Sandbox Code Playgroud)

并部署在firebase上

firebase deploy
Run Code Online (Sandbox Code Playgroud)

Web应用程序无法与API通信

我该怎么做才能解决它?

firebase firebase-hosting angular-cli angular

7
推荐指数
2
解决办法
3889
查看次数

从angular-cli创建的environment.ts文件中访问process.env

我有一个angular-cli应用程序(角度版本4.0.0).我希望能够在从cli创建的environment.ts文件中访问我的环境变量.

例:

export SOME_VARIABLE=exampleValue
Run Code Online (Sandbox Code Playgroud)

当我构建我的角度应用程序时,我想在"SOME_VARIABLE"字段中填充"exampleValue".

// environment.ts

export const environment = {
    production: false,
    SOME_VARIABLE: process.env.SOME_VARIABLE
};
Run Code Online (Sandbox Code Playgroud)

不幸的是,process.env在此文件中不可用.我怎样才能访问它?

angular-cli angular

7
推荐指数
1
解决办法
3010
查看次数

Angular 4 + Cordova +设备就绪

在Cordova上运行(或引导)基于angular-cli的应用程序的最佳方法是什么?

注意:这适用于使用多个Cordova插件的Angular 4.x应用程序.

选项A:post ng build,在你的www/index.html(www是Cordova文件夹)中你应该做以下的事情:

<script src="cordova.js"></script>
<script>
document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
  console.log('onDeviceReady has been called. Lets start loading JS files.');
  var url = ['inline.bundle.js', 'polyfills.bundle.js', 'styles.bundle.js', 'vendor.bundle.js', 'main.bundle.js'];
  for(var i = 0; i < url.length; i++){
    loadJSFile(url[i]);
  }
}

function loadJSFile(url) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    head.appendChild(script);
}
</script>
Run Code Online (Sandbox Code Playgroud)

要么,

选项B:onDeviceReady()可以在main.ts(引导AppModule之前)或app.component.ts中的某个地方.

我尝试过选项A,但我的应用程序在iPad上加载时间过长.所以我想知道我是否遵循了良好的方法.提前感谢您的建议.

cordova angular-cli angular

7
推荐指数
2
解决办法
4302
查看次数

为什么Angular-CLI'ng build'显示"被杀"?

当我添加一个新模块时,ng build只需要处理killed.

在此输入图像描述

angular-cli angular

7
推荐指数
2
解决办法
5151
查看次数

Angular 5 webpack编译错误

升级到Angular 5和Cli 1.5后,ng serve我收到一个错误:

ERROR in ./node_modules/@stomp/ng2-stompjs/index.ts
    Module build failed: Error: ...\project\node_modules\@stomp\ng2-stompjs\index.ts is not part of the compilation output. Please check the other error messages for details.
        at AngularCompilerPlugin.getCompiledFile (...\project\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)
        at plugin.done.then (...\project\node_modules\@ngtools\webpack\src\loader.js:467:39)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)
     @ ./src/app/app.module.ts 27:0-63
     @ ./src/main.ts
     @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
Run Code Online (Sandbox Code Playgroud)

我试图添加include到我的tsconfig.app.json所以它看起来像这样:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "include": [
    "../node_modules/@stomp/**/*.ts"
  ],
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我试过重新运行ng …

angular-cli angular angular5

7
推荐指数
1
解决办法
7660
查看次数

使用AOT时,注入时会丢弃对传递给forRoot的对象的更改

概观

我看到奇怪的行为,因为通过解构赋值(或Object.assign)添加到对象的属性在传递时会出现,forRoot但在注入服务时不存在.此外,初始化后进行的更新在传递到forRoot服务时存在但在注入服务时不存在.这仅在使用AOT构建时发生.

我创建了一个重现问题的最小项目:https: //github.com/bygrace1986/wat

包版本

  • 角度:5.2.0
  • angular-cli:1.6.4(我的应用),1.7.4(我的测试)
  • 打字稿:2.4.2

建立

创建一个具有静态forRoot方法的模块,该方法将接受一个对象,然后通过它提供InjectionToken并注入到服务中.

TestModule

import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';

import { TestDependency, TEST_DEPENDENCY, TestService } from './test.service';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: []
})
export class TestModule {
  static forRoot(dependency?: TestDependency): ModuleWithProviders {
    return {
      ngModule: TestModule,
      providers: [
        TestService,
        { provide: TEST_DEPENDENCY, useValue: dependency }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

TestService的

import …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular2-aot angular

7
推荐指数
1
解决办法
941
查看次数

angular-cli库创建辅助入口点

我正在尝试在我的角度npm包中创建我认为称为辅助入口点的东西。我想要以下两个切入点

@scope/data-service
@scope/data-service/models
Run Code Online (Sandbox Code Playgroud)

使用angular-cli生成基本包会生成以下结构

scope
????data-service
    ?   karma.conf.js
    ?   ng-package.json
    ?   ng-package.prod.json
    ?   package.json
    ?   tsconfig.lib.json
    ?   tsconfig.spec.json
    ?   tslint.json
    ?
    ????src
        ?   public_api.ts
        ?   test.ts
        ?
        ????lib
                data-service.component.spec.ts
                data-service.component.ts
                data-service.module.ts
                data-service.service.spec.ts
                data-service.service.ts
Run Code Online (Sandbox Code Playgroud)

根据ng-packagr 文档,您可以在名为datas的数据服务下添加一个文件夹,然后package.json在该文件夹中添加第二个文件夹,但是ng-packagr似乎使用的结构与angular-cli略有不同。理想情况下,我正在尝试对类似于https://github.com/angular/angular/tree/master/packages/common的结构进行建模,但只要公开了@scope/data-service,@scope/data-service/models我就会很高兴。

当我尝试创建类似于ng-packager建议的结构时,我得到了

error TS6059: File 'C:/projects/data-service-app/projects/scope/data-service/models/src/index.ts' is not under 'rootDir' 'C:\projects\data-service-app\projects\scope\data-service\src'. 'rootDir' is expected to contain all source files.

当我将models目录移动到data-service\src目录中时,我的入口点是

@scope/data-service
@scope/data-service/src/models
Run Code Online (Sandbox Code Playgroud)

如何摆脱二级入口上的src?

使用angular-cli时,使用辅助入口点创建库的正确方法是什么?

angular-cli angular angular-library ng-packagr

7
推荐指数
2
解决办法
2228
查看次数

更新到 Angular 10 错误:无法将“tsconfig.json”解析为 JSON AST 对象

我正在尝试将 Angular 9 应用程序更新为 Angular 10 并出现错误:

> Removing "Solution Style" TypeScript configuration file support.
× Migration failed: Failed to parse "tsconfig.json" as JSON AST Object. PropertyNameExpected at location: 571.
  See "C:\Users\F11K\AppData\Local\Temp\ng-T8Bgiu\angular-errors.log" for further details.
Run Code Online (Sandbox Code Playgroud)

这是日志文件的内容:

[error] Error: Failed to parse "tsconfig.json" as JSON AST Object. PropertyNameExpected at location: 571.
    at JSONFile.get JsonAst [as JsonAst] (C:\Users\F11K\Documents\server\angular-client\node_modules\@schematics\angular\utility\json-file.js:33:19)
    at JSONFile.get (C:\Users\F11K\Documents\server\angular-client\node_modules\@schematics\angular\utility\json-file.js:41:61)
    at C:\Users\F11K\Documents\server\angular-client\node_modules\@schematics\angular\migrations\update-10\remove-solution-style-tsconfig.js:33:71
    at MergeMapSubscriber.project (C:\Users\F11K\AppData\Local\Temp\angular-cli-packages-dD436h\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\rules\call.js:75:24)
    at MergeMapSubscriber._tryNext (C:\Users\F11K\AppData\Local\Temp\angular-cli-packages-dD436h\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:67:27)
    at MergeMapSubscriber._next (C:\Users\F11K\AppData\Local\Temp\angular-cli-packages-dD436h\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:57:18)
    at MergeMapSubscriber.Subscriber.next (C:\Users\F11K\AppData\Local\Temp\angular-cli-packages-dD436h\node_modules\@angular\cli\node_modules\rxjs\internal\Subscriber.js:66:18)
    at Observable._subscribe (C:\Users\F11K\AppData\Local\Temp\angular-cli-packages-dD436h\node_modules\@angular\cli\node_modules\rxjs\internal\util\subscribeToArray.js:5:20)
    at Observable._trySubscribe (C:\Users\F11K\AppData\Local\Temp\angular-cli-packages-dD436h\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:44:25)
    at …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli angular

7
推荐指数
2
解决办法
2305
查看次数