我刚刚开始《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)
下面是在我的 Windows 10 机器上运行的 Nodejs 和 Angular CLI 版本。
Angular CLI:8.3.5 节点:10.16.3 操作系统:win32 x64 Angular:8.2.7
我已经创建了 jenkins 作业来在我的本地主机中构建 Angular 应用程序。
问题就在这里,当我运行基于 jenkins job(Freestyle)的项目时,使用此命令“C:\Angular>npm install --save-dev @angular/cli@latest && ng v”第一个安装命令可以完美运行,没有任何问题,但是当它移动到下一个命令“ng v”时,整个错误如下所示:
“ng”不被识别为内部或外部命令、可操作程序或批处理文件。构建步骤“执行 Windows 批处理命令”将构建标记为失败已完成:失败
注意:但是相同的 cmd“npm install --save-dev @angular/cli@latest && ng v”在 powershell 中按照我们的预期工作。
你能在这方面提供一些帮助吗?
升级到 Angular 9 后,我的一些服务扩展的抽象类会自动使用@injectableAngular 9 迁移指南中所写的装饰。
我的应用程序上的一切正常。
但是我不明白为什么抽象类必须被装饰,因为扩展它们的具体类确实有@injectable装饰器。
我还阅读了这个问题Angular library module injection service with abstract class并建议@injectable从抽象中删除。
那么我应该删除装饰器吗?
这只是将装饰器添加到我的摘要中的 Angular“错误”吗?
此外,我注意到@directive装饰器已添加到用于实现组件的其他抽象类中。
我不断收到以下错误:
[ng] ERROR in src/app/home/home.page.ts(34,10): error TS2339: Property 'router' does not exist on type 'HomePage'.
Run Code Online (Sandbox Code Playgroud)
我正在尝试将Wordpress 与 Ionic 4结合起来,到目前为止我设法从我的网站获取最近的帖子。现在我想让这些可点击并导航到它们,但由于我的代码片段中的这段代码,我收到了上面提到的错误home.page.ts
openPost(postId) {
this.router.navigateByUrl('/post/' + postId);
}
Run Code Online (Sandbox Code Playgroud)
完整页面:
import { Router } from '@angular/router';
import { Component } from '@angular/core';
import { LoadingController } from '@ionic/angular';
import { WordPressRestapiService, Post } from '../services/wordpress-restapi.service';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
categoryId: number;
private posts : Post[] = [];
constructor(
public loadingController: LoadingController, …Run Code Online (Sandbox Code Playgroud) 我希望count和groupby(sqlite)sql查询的两行显示在文本区域中,但是它仅显示第一行。
当我将conn.close()语句放置在“ while”块之外时,它仅显示第二行,而忽略第一行
@FXML
private void viewResult(ActionEvent event)
{
try
{
Connection conn = dbConnection.getConnection();
Statement resultStmt = conn.createStatement();
ResultSet rs = resultStmt.executeQuery("select candidate, count(candidate) from voteResult group by candidate");
while (rs.next()) {
String news = rs.getString(1)+" "+rs.getString(2);
this.result.setText(news);
conn.close();
}
}
catch (SQLException e)
{
System.err.println("Error " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
预期结果应如下所示:
JOSEPH THANKGOD 4
ORJI DANIEL 1
Run Code Online (Sandbox Code Playgroud)