我最近将我的应用程序升级到了 angular 7。我正在尝试使用特定环境运行我的 ng e2e 测试。此外,我不希望每次为应用程序运行 e2e 测试时都运行新服务器。
使用 angular 5 时,我曾经使用 CLI 按照以下方式进行操作:
ng e2e -e test --config protractor.conf.test.js --no-serve
Run Code Online (Sandbox Code Playgroud)
我的测试环境在 environment.test.ts 文件中设置,量角器配置(baseURL 和无头浏览器)在 protractor.conf.test.js 文件中设置。每次运行 e2e 测试时,我都使用 no-serve 标志停止运行新服务器。
对于 angular 7,我在 angular.json 文件中进行了以下更改:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"sample-app": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": ["src/assets", "src/favicon.ico"],
"styles": ["src/styles.css"],
"scripts": []
},
"configurations": …Run Code Online (Sandbox Code Playgroud) 当我运行 npm audit 命令时
=== npm 审计安全报告 ===
`Manual Review
Some vulnerabilities require your attention to resolve
Visit https://go.npm.me/audit-guide for additional guidance `
High ? Arbitrary File Overwrite
Package ? tar
Patched in ? >=4.4.2
Dependency of ? @angular-devkit/build-angular [dev]
Path ? @angular-devkit/build-angular > node-sass > node-gyp >tar
More info ? https://nodesecurity.io/advisories/803
Run Code Online (Sandbox Code Playgroud)
它的说法found 1 high severity vulnerability in 42611 scanned packages
1 vulnerability requires manual review。由于它与 相关@angular-devkit/build-angular,我担心它是否会在我的项目中产生任何其他问题。
当我运行 npm audit fix 命令时
npm WARN optional SKIPPING …Run Code Online (Sandbox Code Playgroud) 我有一个用于演示目的的角度模块(DevShowcaseModule)。此模块不应包含在生产版本中。为了向最终用户隐藏此演示并防止生产中的演示代码错误。
环境:
这是我的 app-routing.module.ts
{
path: APP_NAV_ITEMS.DEV_SHOWCASE,
canActivate: [ AuthGuard ],
loadChildren: './_dev-showcase/dev-showcase.module#DevShowcaseModule',
}
Run Code Online (Sandbox Code Playgroud)
我试图从 tsconfig.json 中排除模块文件夹。但它不起作用,我仍然可以调用路由并加载演示模块。
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"importHelpers": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"exclude": [
"app/_dev-showcase/*"
]
}
Run Code Online (Sandbox Code Playgroud)
知道如何正确地做到这一点吗?
谢谢!
将 angular 7 更新为 angular 8,我angular/cli angular/core使用命令成功更新$ ng update @angular/cli@v8 @angular/core@v8。而且我也使用了有角度的材料,所以我想更新材料,然后我用$ ng update @angular/material@v8. 但是在运行命令后我得到了Repository is not clean. Please commit or stash any changes before updating.
所以我在更改 git 之前提交,然后我再次尝试使用相同的命令,然后也得到相同的消息。现在没有要提交或存储的文件。
这是package.json文件的依赖关系:
"dependencies": {
"@angular/animations": "^8.0.0",
"@angular/cdk": "^7.3.7",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/forms": "^8.0.0",
"@angular/material": "^7.3.7",
"@angular/platform-browser": "^8.0.0",
"@angular/platform-browser-dynamic": "^8.0.0",
"@angular/router": "^8.0.0",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"ngx-loading": "^3.0.1",
"rxjs": "6.5.2",
"underscore": "^1.9.1",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.800.0",
"@angular/cli": "~8.0.2", …
我想知道是否有办法根据环境配置angular.json文件的脚本部分.
我想在生产环境中包含一个特定的脚本(Myscript.js).
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/slick-carousel/slick/slick.min.js",
"./src/assets/scripts/Myscript.js"
]
Run Code Online (Sandbox Code Playgroud)
我没有在文档中找到任何关于此的内容.可能吗?
用于将cli版本从v7项目更新到v8的ng upgrade命令失败。
首先手动尝试升级cli也会失败。
ng update @angular/cli
Run Code Online (Sandbox Code Playgroud)
您的全局Angular CLI版本(8.0.1)大于本地版本(7.3.9)。使用本地Angular CLI版本。
程序包"@angular/compiler-cli"与“ typescript” 具有不兼容的对等依赖性(requires ">=3.1.1 <3.3", would install "3.4.5")。发现不兼容的对等项依赖关系。往上看。
我刚刚开始《Karma》和《Jasmine》。我陷入了无法对组件执行单元测试的困境,我想要触发的函数与*ngIf某些特定值的按钮的条件绑定。
import { Component, Input, EventEmitter, Output } from '@angular/core';
import { Location } from '@angular/common';
import { XService } from 'src/app/services/x-service';
@Component({
selector: 'my-head-component',
templateUrl: './headComponent.html',
styleUrls: ['./head.scss']
})
export class MyComponent {
@Input() variableX = '';
@Output() outVar1: EventEmitter<string> = new EventEmitter();
@Output() outVar2: EventEmitter<string> = new EventEmitter();
y1='';
y2='';
constructor(private location: Location,
private xServ:XService ) { }
lookBack() {
this.location.back();
}
doSearch() {
this.y1= '';
this.y2 = '';
this.outVar1.emit(this.y1);
this.outVar2.emit(this.y2);
}
...
}
Run Code Online (Sandbox Code Playgroud)
我有一个 angular-cli 应用程序,当我给出ng build命令时,它会创建包含 index.html 文件的构建文件。
在 index.html 文件中,脚本路径如下所示:
<script type="text/javascript" **src="runtime.js"**></script>
<script type="text/javascript" **src="polyfills.js"**></script>
<script type="text/javascript" **src="styles.js"**></script>
<script type="text/javascript" **src="vendor.js"**></script>
<script type="text/javascript" **src="main.js"**></script>Run Code Online (Sandbox Code Playgroud)
但我想像下面那样改变那个脚本,
<script type="text/javascript" **src="~/runtime.js"**></script>
<script type="text/javascript" **src="~/polyfills.js"**></script>
<script type="text/javascript" **src="~/styles.js"**></script>
<script type="text/javascript" **src="~/vendor.js"**></script>
<script type="text/javascript" **src="~/main.js"**></script>Run Code Online (Sandbox Code Playgroud)
是否可以在不使用查找和替换方法的情况下更改路径?
当我运行 Angular Cli 的早期版本时,ng g service services/MyService它创建了:
services/my-service/my-service.service.ts
services/my-service/my-service.service.spec.ts
Run Code Online (Sandbox Code Playgroud)
但现在它创造了
services/my-service.service.ts
services/my-service.service.spec.ts
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以返回其他行为而无需编写详细信息ng g service services/my-service/MyService ?我没有找到任何相关内容,但也许我没有使用正确的关键字。
我使用的是 angular 7.1.0,目前我使用的是primeng 6.1.6。如何将我的版本升级到primeng 7.1.0。我尝试了一些命令,例如npm install primeng --save。但它不起作用。它显示了一些这样的错误......
PS E:\srini_vision\skopiq-vision-web\angular> npm install primeng --save npm WARN skopiqrpa@1.0.0 无描述 npm WARN skopiqrpa@1.0.0 无存储库字段。npm WARN skopiqrpa@1.0.0 没有许可证字段。
npm 错误!路径 E:\srini_vision\skopiq-vision-web\angular\node_modules.bin\semver.cmd npm ERR!代码 EEXIST npm ERR!拒绝删除 E:\srini_vision\skopiq-vision-web\angular\node_modules.bin\semver.cmd: ..@angular-devkit\build-angular\node_modules\semver\bin\semver 符号链接目标不受 npm E 控制:\srini_vision\skopiq-vision-web\angular\node_modules\semver npm ERR!文件存在:E:\srini_vision\skopiq-vision-web\angular\node_modules.bin\semver.cmd npm ERR!把它移开,然后再试一次。
npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!C:\Users\T5071\AppData\Roaming\npm-cache_logs\2019-04-09T06_15_56_988Z-debug.log PS E:\srini_vision\skopiq-vision-web\angular> npm run ng --version 5.6.0
angular-cli-v7 ×10
angular ×7
angular-cli ×5
angular7 ×2
typescript ×2
devkit ×1
e2e-testing ×1
git ×1
github ×1
jasmine ×1
ng-upgrade ×1
node.js ×1
npm ×1
production ×1