我正在从版本4升级Angular应用程序到版本6.一切正常运行ng serve.现在的问题是我们的一些规范文件失败了[object ErrorEvent] thrown.我以前见过这个并且通常可以用--sourceMap=false旗帜运行测试以查看更详细的报告,但现在我仍然得到这个模棱两可的错误.我已经检查过没有任何组件有任何未定义的输入.经过一些研究后,我发现有些人遇到了jasmine-core 3.0.0的问题并收到了这个错误,直到他们回到2.99.0,但这对我也没有任何作用.
关于所有这一切最奇怪的部分是,我可以xdescribe通过此错误失败的规范(或所有规范)然后不同的失败,之前没有失败.
这是package.json
{
"name": "enterprise-frontend",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test --browsers=Chrome --code-coverage",
"lint": "ng lint --type-check",
"e2e": "ng e2e",
"compodoc": "./node_modules/.bin/compodoc -p tsconfig.json -s"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/cdk": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/material": "^6.0.2",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/router": "^6.0.2",
"@auth0/angular-jwt": "^2.0.0",
"@ngrx/effects": "^6.0.1", …Run Code Online (Sandbox Code Playgroud) 我第一次使用离子4的beta.我尝试在登录页面上禁用菜单,但是我遇到了一些麻烦.
我用ionic-cli和sidemenu模板创建了应用程序,然后生成了一个登录页面.
我<ion-split-pane>从app.component.html中删除了它
我修改了app-routing.module.ts以重定向到我的登录屏幕.在我的登录文件中,我尝试放置一个ngOnInit事件来禁用此特定页面上的菜单
import { Component, OnInit, AfterContentInit, AfterViewInit,OnDestroy } from '@angular/core';
import { MenuController } from '@ionic/angular';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit, AfterContentInit, AfterViewInit,OnDestroy {
constructor(public menuCtrl: MenuController) {}
ngOnInit() {
this.menuCtrl.enable(false);
this.menuCtrl.swipeEnable(false);
}
ngAfterContentInit() {
this.menuCtrl.enable(false);
this.menuCtrl.swipeEnable(false);
}
ngAfterViewInit() {
this.menuCtrl.enable(false);
this.menuCtrl.swipeEnable(false);
}
ngOnDestroy() {
this.menuCtrl.enable(true);
this.menuCtrl.swipeEnable(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在离子菜单中设置了id
<ion-menu swipeEnabled="true" #menu>
Run Code Online (Sandbox Code Playgroud)
并改变我的代码
this.menuCtrl.enable(false, 'menu');
Run Code Online (Sandbox Code Playgroud)
它不起作用,有人可以帮助我.
谢谢
在Angular应用程序中使用外部服务是一项要求。外部服务具有自己的用户界面。因此,我们必须使用给定外部服务URL上的纯HTTP Post请求重定向到外部服务。
有没有一种方法可以从Angular进行非AJAX后期调用,以便屏幕重定向到外部服务网页。
我需要做休息操作和捕捉错误,我这样做:
import { Injectable, } from '@angular/core';
import { Http, Response,Headers} from '@angular/http';
import { map} from 'rxjs/operators';
import { catchError } from 'rxjs/operators';
import { Observable} from 'rxjs';
@Injectable()
export class RESTSERCIVE{
getObject(id: number){
return this.http.get(this.url+"/"+id).pipe(map(
(response: Response)=>{return response.json()},
),
catchError(this.handleErrorObservable)
);
}
handleErrorObservable (error: Response | any)
{
return Observable.throw(error.message || error);
}
}
Run Code Online (Sandbox Code Playgroud)
我不是为什么它给我这个错误.有人可以帮帮我吗?
我从下面了解递归元素(树视图)的概念.
在我的情况下,我想用它与表格; 让我们说递归的简单文本输入.表单的JSON结构如下.
我准备下面的代码.我通过执行下面的代码得到最大调用堆栈大小超过错误.
下面是我的component.html文件.
<form [formGroup]="testForm" (ngSubmit)="onSubmit()">
<div formArrayName="element">
<ng-template #recursiveList let-list>
<div *ngFor="let item of testForm.get('element').controls;let i=index;">
<div [formGroupName]="i">
<input type="text" formControlName="type">
</div>
<!-- {{item.get('element')?.controls?.length}} -->
<div *ngIf="item.get('element')?.controls?.length > 0">
<ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: item.get('element').controls }"></ng-container>
</div>
</div>
</ng-template>
<ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: testForm.get('element').controls }"></ng-container>
</div>
Run Code Online (Sandbox Code Playgroud)
这是component.ts文件.
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup, Validators, FormBuilder, FormArray} from '@angular/forms';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: [
'./test.component.scss' …Run Code Online (Sandbox Code Playgroud) 当我使用angular dotnet创建asp.net核心项目时,new命令不会将angular.json文件(角度6)添加到项目中,因此我们无法使用angular cli.如果我手动添加angular.json文件,项目将在下面给出例外!?
Workspace needs to be loaded before it is used. Error: Workspace needs to be loaded before it is used. at Workspace._assertLoaded (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:59:19) at Workspace.getProjectByPath (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:103:14) at Object.getPackageManager (D:\NetAngular\node_modules\@angular\cli\utilities\config.js:97:35) at UpdateCommand.runSchematic (D:\NetAngular\node_modules\@angular\cli\models\schematic-command.js:74:38) at UpdateCommand.<anonymous> (D:\NetAngular\node_modules\@angular\cli\commands\update.js:70:25) at Generator.next (<anonymous>) at D:\NetAngular\node_modules\@angular\cli\commands\update.js:7:71 at new Promise (<anonymous>) at __awaiter (D:\NetAngular\node_modules\@angular\cli\commands\update.js:3:12) at UpdateCommand.run (D:\NetAngular\node_modules\@angular\cli\commands\update.js:69:16)
Run Code Online (Sandbox Code Playgroud) 我将Angular项目更新为Angular 6,并且不知道如何进行http获取请求.这就是我在Angular 5中的表现:
get(chessId: string): Observable<string> {
this.loadingPanelService.text = 'Loading...';
this.loadingPanelService.isLoading = true;
const url = `${this.apiPathService.getbaseUrl()}api/chess/${chessId}/rating`;
return this.http.get<string>(url)
.catch((error) => {
console.error('API error: ', error);
this.loadingPanelService.isLoading = false;
this.notificationService.showErrorMessage(error.message);
return Observable.of(null);
})
.share()
.finally(() => {
this.loadingPanelService.isLoading = false;
});
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在做的事情.这是应该如何在Angular 6中完成的吗?
...
return this.http.get<string>(url)
.pipe(
catchError(this.handleError),
share(),
finalize(() =>{this.loadingPanelService.isLoading = false})
);
private handleError(error: HttpErrorResponse) {
console.error('API error: ', error);
this.loadingPanelService.isLoading = false;
this.notificationService.showErrorMessage(error.message);
// return an observable with a user-facing error message
return throwError(
'Something bad happened; …Run Code Online (Sandbox Code Playgroud) 我想使用nodejs buildpack将我的angular 6应用程序部署为PCF上的独立应用程序。有没有办法在不增加角度通用功能的情况下做到这一点。
如果不可能,如果我使用静态buildpack部署应用程序,是否可以读取PCF用户提供的环境变量?
我想使用此Angular 6代码实现文件下载:
REST API:
private static final Logger LOG = LoggerFactory.getLogger(DownloadsController.class);
private static final String EXTERNAL_FILE_PATH = "/Users/test/Documents/blacklist_api.pdf";
@GetMapping("export")
public ResponseEntity<FileInputStream> export() throws IOException {
File pdfFile = Paths.get(EXTERNAL_FILE_PATH).toFile();
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity.ok().headers(headers).contentLength(pdfFile.length())
.contentType(MediaType.parseMediaType("application/pdf"))
.body(new FileInputStream(pdfFile));
}
Run Code Online (Sandbox Code Playgroud)
服务:
import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from "@angular/common/http";
import {Observable} from "rxjs/index";
import {environment} from "../../../environments/environment";
import {HttpUtils} from "../common/http-utils";
import { map } from 'rxjs/operators';
import {Http, ResponseContentType} from …Run Code Online (Sandbox Code Playgroud) 我正在将Angular应用程序从v6迁移到v7。除了对枚举进行比较的任何测试以外,其他一切都很好。当我运行测试时,会遇到很多关于枚举的错误,例如
ERROR in src/.../some-thing.component.spec.ts: error TS2345: Argument of type 'PlanDuration.SixMonths' is not assignable to parameter of type 'Expected<PlanDuration.TwelveMonths>'.
Run Code Online (Sandbox Code Playgroud)
运行测试的示例如下所示:
export enum PlanDuration {
SixMonths,
TwelveMonths
}
...
it('should toggle plan duration to six months if the event source id is the toggle duration and the event is not checked', () => {
component.selectedPlanDuration = PlanDuration.TwelveMonths;
component.handleToggle(event);
expect(component.selectedPlanDuration).toBe(PlanDuration.SixMonths); // Tests cannot run because of errors here
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我将枚举值转换为数字,则测试将完美运行!像这样在任何地方更新我的规格都不太理想:
expect(component.selectedPlanDuration).toBe(<number> PlanDuration.SixMonths);
Run Code Online (Sandbox Code Playgroud)
我不确定我是否错过了一些东西package.json。我已经将一个新的angular 7项目与自己的项目进行了比较,并且它们之间的angular core,打字稿,茉莉花和业力版本相同。
如何获得测试以正确比较枚举?下面是我的package.json
"dependencies": {
"@angular/animations": "~7.2.0", …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×9
angular7 ×1
asp.net-core ×1
enums ×1
ionic4 ×1
jasmine ×1
observable ×1
spring ×1
spring-boot ×1
typescript ×1
unit-testing ×1