我的节点版本是16.13.0,我正在使用 Angular 14
以下是我的package.json
{
"name": "my-project",
"version": "01.06.05",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node ./replace.build.js && ng serve --open",
"build": "ng lint && node ./replace.build.js && ng build --configuration=production --build-optimizer --optimization --extract-licenses=false",
"publish": "npm run build",
"test": "ng test",
"lint": "ng lint"
},
"private": true,
"dependencies": {
"@angular/animations": "^14.2.0",
"@angular/cdk": "^14.2.0",
"@angular/common": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/forms": "^14.2.0",
"@angular/material": "^14.2.0",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/router": "^14.2.0",
"@angular/service-worker": "^14.2.0",
"bootstrap": "^5.2.0",
"highcharts": "^10.2.1",
"hover.css": "^2.3.2",
"lodash-es": …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加代理以将源更改为服务器,例如
从http://localhost:4200/api/deaprtment/get/2
到http://localhost:7201/api/department/get/2
请注意,这localhost:4200就是我的角度应用程序运行的地方
是localhost:7201我的 asp.net 服务器运行的内容
我的 proxy-config.json 是
{
"/api": {
"target": "http://localhost:7201",
"secure": false
}
}
Run Code Online (Sandbox Code Playgroud)
它位于 src/proxy-config.json 中
我的 angular.json 是
.
.
.
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "test2:build:production"
},
"development": {
"browserTarget": "test2:build:development",
"proxyConfig": "src/proxy-config.json"
}
},
"defaultConfiguration": "development"
},
.
.
.
Run Code Online (Sandbox Code Playgroud)
当运行时ng serve
它总是给我这个错误:
- 生成浏览器应用程序包(阶段:设置)...发生未处理的异常:代理配置文件 C:\Users\nasse\RiderProjects\Solution2\test2\src\proxy-c onfig.json 包含解析错误:[1, 1] InvalidSymbol 请参阅“C:\Users\nasse\AppData\Local\Temp\ng-T9wrQt\angular-errors.log”了解更多详细信息。
我的 Azure 管道开始失败。我的错误如下:
Node.js version v16.20.2 detected.
The Angular CLI requires a minimum Node.js version of v18.13.
Run Code Online (Sandbox Code Playgroud)
我没有改变任何东西。这是我的管道的一部分:
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
sudo npm install -g @angular/cli
npm install
ng build -c=release --output-path=web/wwwroot
displayName: 'npm install and build'
Run Code Online (Sandbox Code Playgroud)
两周前该脚本有效。
我的问题是,如何在Azure管道中修复它?我正在使用 Microsoft 托管代理
每当我使用ng new "your-app-name"命令创建新的角度应用程序时,它都不会app.module.ts在项目结构中创建文件,并且角度 cli 中不会出现任何提示询问是否包含路由。另外,在 main.ts 文件中,新应用程序始终作为 bootstrapApplication 创建,但我想要 platformBrowserDynamic。请提出一个解决方案。
我尝试重新安装 Node.js 和 Angular 几次,甚至交叉检查 Angular.json 配置,但仍然没有成功。我使用的是 MacBook (M1)
我想使用Firebase模块"Firebase.ServerValue.TIMESTAMP"将日期保存到firebase服务器,并使用服务器生成的时间戳.
如何配置将firebase导入为angular2项目中的模块.
我正在使用Angular2,angular-cli,angularFire2等.以下是配置设置.
System-config.ts
/** Map relative paths to URLs. */
const map: any = {
firebase: 'vendor/firebase/lib/firebase-web.js',
angularfire2: ' vendor/angularfire2'
};
/** User packages configuration.*/
const packages: any = {
angularfire2: {
defaultExtension: 'js',
main: 'angularfire2.js'
}
};
Run Code Online (Sandbox Code Playgroud)
角-CLI-build.js
/* global require, module */
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)',
// below are the AngularFire entries
'angularfire2/**/*.js',
'firebase/lib/*.js'
]
});
};
Run Code Online (Sandbox Code Playgroud) 在Angular 2中加载单个节点模块,在wiki中很好地描述了一个angular-cli bootstraped项目.只是好奇,如何在一个用angular-cli引导的项目中很好地加载一个更复杂的节点模块?
例如angular2-apollo依赖于几个子依赖,如apollo-client,graphql,lodash,......
我添加了节点模块 angular-cli-build.js
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'...',
'angular2-apollo/**'
]
});
};
Run Code Online (Sandbox Code Playgroud)
并注册了节点模块插件system-config.js与
const barrels: string[] = [
// ...
// Thirdparty barrels.
'rxjs',
'angular2-apollo',
// App specific barrels.
// ...
];
// ...
// Apply the CLI SystemJS configuration.
System.config({
map: {
'@angular': 'vendor/@angular',
'rxjs': 'vendor/rxjs',
'angular2-apollo':'vendor/angular2-apollo/build/src',
'main': 'main.js',
},
packages: cliSystemConfigPackages
});
Run Code Online (Sandbox Code Playgroud)
然而,这只是加载angular2-apollo.angular2-apollo的子依赖性没有得到加载.如何在angular-cli bootstraped项目中加载system.js的子依赖项?
我正在使用angular-cli@1.0.0-beta.14(webpack)和primeng@1.0.0-beta.15.
创建一个新的angular-cli项目后,我做了一些更改来添加primeng:
package.json上的1:
"primeng": "^1.0.0-beta.15"
Run Code Online (Sandbox Code Playgroud)
2 on angular-cli.json:
"styles": [ "styles.css", "../node_modules/primeng/resources/themes/omega/theme.css", "../node_modules/font-awesome/css/font-awesome.min.css", "../node_modules/primeng/resources/primeng.min.css" ],
"scripts": [ "../node_modules/primeng/primeng.js" ]
Run Code Online (Sandbox Code Playgroud)
app.module.ts上的3:
@NgModule({ declarations: [ AppComponent ],
imports: [ BrowserModule, FormsModule, HttpModule, PanelModule ],
providers: [], bootstrap: [AppComponent] }) export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
问题:
未捕获的ReferenceError:未定义require模块'AppModule'导入的意外值'undefined'
任何帮助将primeng添加到angular-cli ...我们会很棒!:)
上周,我开始使用Angular-Cli创建的Angular 2构建一个投资组合网站.这个投资组合网站是一项学校作业.
最终要求之一是网站可以在没有网络服务器的情况下运行.
当我在网络服务器上打开网站(用它构建之后ng build),我完全没有问题加载它.但是当我在浏览器中本地打开它时,我会收到每个javascript文件上找不到的404文件.
这些javascript文件与下面显示的索引页面位于同一目录中.
这是我生成的index.hmtl ng build.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hallo, ik ben Maarten.</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="assets/favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
</head>
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="inline.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="scripts.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是在浏览器中打开索引文件时找不到文件.
是否可以在没有Web服务器的情况下使用Angular-Cli运行Angular 2项目构建?
谢谢,
Maarten Paauw
我是Angular 2的新手.我正在使用ng2-charts作为我的角度2项目.ng2-charts要求Chart.js嵌入我的应用程序头中,如下所示:
<script src="node_modules/chart.js/src/chart.js"></script>
Run Code Online (Sandbox Code Playgroud)
从我的index.html我无法访问nodes_modules(错误:GET http:// localhost:4200/node_modules/chart.js/dist/Chart.js).根据我的理解,因为node_modules没有"编译"到dist文件夹中.
因此,我需要将chart.js添加为全局库安装(如下所述:https://github.com/angular/angular-cli#global-library-installation)
当我这样做时,我得到"Uncaught ReferenceError:require is not defined".我认为这是因为chart.js正在systemJS之前加载,因此不知道'require'.我尝试在apps [0] .scripts中的chart.js之前添加systemJS,但这也不起作用.
这是我的angular-cli.json:
{
"project": {
"version": "1.0.0-beta.16",
"name": "poc1-iot-monitor-frontend"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": "assets",
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css"
],
"scripts": [
"../node_modules/systemjs/dist/system.src.js",
"../node_modules/chart.js/src/chart.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js" …Run Code Online (Sandbox Code Playgroud) 我正在使用角度为2.1的最新角度cli.我想编写的组件测试很简单:从服务中获取一些数据并显示它.
当数据仅显示在段落中时,它可以工作,但当它绑定到textarea时,它不会.
以下是我的模板的摘录:
async
和相应的测试:
<p *ngIf="!isBusy" class="twain">
<i>{{settings.blockLoginMessage}}</i>
</p>
<textarea
id="blockLoginMessage"
name="blockLoginMessage"
[(ngModel)]="settings.blockLoginMessage"
class="form-control">
</textarea>
Run Code Online (Sandbox Code Playgroud)
});
有没有人提示为什么这不起作用?此外,我的异步和伪同步尝试完全失败,当我的Promises延迟时,如上所述
angular-cli ×10
angular ×7
node.js ×3
javascript ×2
npm ×2
azure ×1
azure-devops ×1
eslint ×1
firebase ×1
json ×1
node-modules ×1
primeng ×1
typescript ×1
unit-testing ×1
webpack ×1