https://github.com/angular/angular-cli#proxy-to-backend这里是一个如何代理后端的指令.我一步一步做了所有事情仍然没有代理请求.
8080 - 我的Express后端4200 - 我的Angular2前端
在Angular2项目中,我的文件proxy.cons.json内容如下:
{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}
Run Code Online (Sandbox Code Playgroud)
在Angular2 package.json中,我将start过程更改为"start": "ng serve --proxy-config proxy.conf.json"
当我输入指挥官内部npm start时,我可以看到Proxy created: /api -> http://localhost:8080.好吧,到目前为止我觉得很好.
我正在尝试发送请求(Angular2)
constructor(private http: Http) {
this.getAnswer();
}
getAnswer(): any {
return this.http.get("/api/hello")
.subscribe(response => {
console.log(response);
})
}
Run Code Online (Sandbox Code Playgroud)
我收到了一个错误http://localhost:4200/api/hello 404 (Not Found).我们可以看到,没有任何代理.为什么?我做错什么了吗?
要清楚.当我手动去http://localhost:8080/hello,一切正常.在后端方面没有什么可以寻找的.
我知道这是一种糟糕的做法,但与我配对:
我正在使用Angular-CLI,特别ng g是生成我的所有类,但是,我对任何测试文件都不感兴趣*.spec.ts,我知道有两个标志(--inline-template,--inline-style)来处理内联CSS和HTML而不是分离文件.对于spec,默认标志设置为true--spec
所以对于每次运行,是的,我可以这样做 ng g c foo --it --is --spec=false
但是如何全局禁用测试文件的创建?它有默认设置吗?
拉什利,我做了一些像(不起作用)的东西:
ng set spec=false --global
然后尝试src/tsconfig.json通过填充exclude数组来配置ts设置文件.
"exclude": [
"**/*.spec.ts"
]
Run Code Online (Sandbox Code Playgroud) 我是angular2的新手,我试图用cli创建一个项目,但当我尝试更改在angular-cli.json中添加它的CSS时,我检测到这个文件没有创建...
我可以手动创建或者此文件已被更改为另一个吗?
谢谢!!
我正在使用角度2.4.9进行应用程序开发,所以我需要使用特定版本的ng cli而不是最新版本.
我知道下面的命令将安装最新版本的ng cli
npm install -g @angular/cli
Run Code Online (Sandbox Code Playgroud)
但是如何安装特定版本的ng cli?
ng update
Run Code Online (Sandbox Code Playgroud)
无法从工作区根目录解析“@angular-devkit/schematics”包。这可能是由于不受支持的节点模块结构所致。请同时删除“node_modules”目录和包锁文件;然后重新安装。如果这不能解决问题,请在工作区中临时安装“@angular-devkit/schematics”包。更新完成后可以将其删除。
从 Angular 11 更新到 12 后,ng serve现在抛出错误:
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/_colors.scss:1:4: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/custom-bootstrap.scss:1:1: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/global.scss:296:12: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/mdsl-composer/mdsl-composer-variables.scss:103:1: Unknown word
You tried to parse SCSS with the …Run Code Online (Sandbox Code Playgroud) 我已全局升级了我的Angular CLI,但我的项目使用的是旧版本的角度CLI,所以我想全局降级我的Angular CLI.
到目前为止,我可以用角度cli创建的最小的捆绑是运行
ng build --aot true -prod
我想知道构建过程是否也删除了未使用的CSS类,例如从bootstrap?
如果不是,我怎么能添加像purifycss这样的库?
编辑2018年4月
我仍然没有找到任何令人满意的解决方案来解决他的问题,特别是与带有角度的延迟加载模块兼容的解决方案...
干杯
每当我创建一个新组件时,有没有办法摆脱Angularjs 2中的spec.ts文件.我知道这是出于测试目的,但如果我不需要它会怎样.
可能有一些设置来禁用此特定测试文件.
我曾经能够通过导入语句在Angular中使用lodash方法,如下所示:
import {debounce as _debounce} from 'lodash';
Run Code Online (Sandbox Code Playgroud)
我现在在使用该语句时收到以下错误:
'"{...}/node_modules/@types/lodash/index"' has no exported member 'debounce'.
Run Code Online (Sandbox Code Playgroud)
唯一能编译而没有错误的是这句话:
import * as _ from 'lodash';
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我_debounce()改为_.debounce().这是唯一(和/或正确)的方式吗?有没有办法只进口去抖,还是由于"树木"而无关紧要?我意识到我可以编写自己的去抖函数,但我主要对"正确"的方法感兴趣.
ps我尝试过的其他变体(每种变体都有一些与之相关的错误):
import {debounce as _debounce } from 'lodash/debounce';
import * as _debounce from 'lodash/debounce';
import debounce = require('lodash/debounce');
Run Code Online (Sandbox Code Playgroud)
仅供参考...我使用以下版本:
角度:2.4.5
打字稿:2.1.5
Angular-cli:1.0.0-beta.26
angular-cli ×10
angular ×9
typescript ×2
angular2-aot ×1
angular2-cli ×1
css ×1
json ×1
minify ×1
npm ×1
proxy ×1
webpack ×1