我想将带有一些搜索参数的http.get请求发送到我的webapi以获取学生列表.我找到了一些关于如何执行此操作的示例,但在完成示例之后,我得到了这个奇怪的错误:
[ts]
Type 'URLSearchParams' is not assignable to type 'URLSearchParams'. Two different types with this name exist, but they are unrelated.
Property 'rawParams' is missing in type 'URLSearchParams'.
Run Code Online (Sandbox Code Playgroud)
这是我的组件:
import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map'
import { User } from '../_models/user';
@Injectable()
export class UserService {
options = new RequestOptions({ 'headers': new Headers({ 'Content-Type': 'application/json' })});
constructor(private http: Http) {
}
createAccount(newUser: User){
return this.http.post('http://localhost:64792/api/students', JSON.stringify(newUser), this.options)
.map((response: Response) …
Run Code Online (Sandbox Code Playgroud) 起初,我的测试类上方有以下注释:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@AutoConfigureMockMvc
Run Code Online (Sandbox Code Playgroud)
使用该配置,它会尝试连接到我的数据库,如果我的数据库未运行,则会出现此错误:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
Run Code Online (Sandbox Code Playgroud)
我希望我的测试在没有任何数据库连接的情况下运行,这就是我尝试更改注释的原因,所以我的测试类现在如下所示:
@RunWith(SpringRunner.class)
@DataJpaTest
@WebMvcTest(CitizenController.class)
@AutoConfigureMockMvc
public class CitizenControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private CitizenRepository citizenRepository;
@MockBean
private WeeklyCareRepository weeklyCareRepository;
@MockBean
private SubCategoryCareRepository subCategoryCareRepository;
@Autowired
private ObjectMapper objectMapper;
private static List<Citizen> mockCitizenList;
private String citizenJson;
Run Code Online (Sandbox Code Playgroud)
但是,我现在收到另一个错误:
java.lang.IllegalStateException: …
Run Code Online (Sandbox Code Playgroud) 目前,我正在使用我发现的长度限制:
<input #password="ngModel" type="password" name="password" minlength="5" maxlength="30" pattern="((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})" required ngModel>
Run Code Online (Sandbox Code Playgroud)
它有效,但我不想在最后限制长度.我对正则表达式了解不多,所以我认为{6,20}
最后删除会完成工作,但我错了.
所以我的问题是:如何在没有长度限制的情况下使这个正则表达式工作?谢谢!
我很困扰。我已经很久没有问题了,现在我突然不能再部署了。我不记得做了任何可能导致这种情况的事情。
我有 3 种不同的云功能。当我跑步时,firebase deploy
我得到了每个似乎都相同的错误:
! functions[generateThumbs(europe-west1)]: Deployment error.
Build failed: {"error": {"canonicalCode": "INVALID_ARGUMENT", "errorMessage": "`npm_install` had stderr output:\nnpm WARN tar ENOENT: no such file or directory, lstat '/workspace/node_modules/.staging/sharp-261f9e9e/docs/image'\nnpm WARN tar ENOENT: no such file or directory, open '/workspace/node_modules/.staging/firebase-admin-a1197e24/lib/auth/token-verifier.js'\nnpm WARN tar ENOENT: no such file or directory, open '/workspace/node_modules/.staging/@types/lodash-973f4ada/common/math.d.ts'\nnpm WARN tar ENOENT: no such file or directory, open '/workspace/node_modules/.staging/sharp-261f9e9e/docs/index.md'\nnpm WARN tar ENOENT: no such file or directory, open '/workspace/node_modules/.staging/@types/lodash-973f4ada/common/number.d.ts'\nnpm WARN tar ENOENT: no such file or directory, open …
Run Code Online (Sandbox Code Playgroud) 我几乎找不到这个.谷歌上出现的几乎所有东西都是关于Angular 1的,而我发现的Angular 2并没有起作用(http://www.talkinghightech.com/en/angular-2-end-2-end-testing/).
我正在寻找一种方法来禁用CSS动画和我的角度2组件上的动画.
我想使用highcharts中的spiderweb图表,这需要我更多地导入highcharts,但我无法弄清楚如何做到这一点.目前,这就是我将highcharts添加到我的项目中的方式,来自app.module.ts
:
import { ChartModule } from 'angular2-highcharts';
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';
import * as Highcharts from 'highcharts/highstock';
imports: [
ChartModule
]
providers: [{
provide: HighchartsStatic,
useValue: Highcharts
}],
Run Code Online (Sandbox Code Playgroud)
当我尝试像这样导入它时:
import * as HighchartsMore from 'highcharts/highcharts-more';
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Module '"c:/pdws-view-v2/node_modules/@types/highcharts/highcharts-more"' resolves to a non-module entity and cannot be imported using this construct.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我的应用程序中存在内存泄漏问题,希望你们能提供帮助。经过检查问题,我得出的结论是它是由以下代码引起的:
我有几个 html 文件,ngFor
用于为数组中的每个对象创建一些 html 代码:
<div class="patient-box level-1" *ngFor="let bed of beds">
more html..
</div>
Run Code Online (Sandbox Code Playgroud)
在组件中,我订阅了一个 observable,它不时发出一个新数组:
updateBeds(purge: boolean) {
this._beds.next(this.bedsData);
}
Run Code Online (Sandbox Code Playgroud)
这是当我收到新数组时发生的情况:
this.patientService.beds.subscribe(updatedBeds => {
this.beds = updatedBeds;
this.sortBeds(this.sortProperty);
});
Run Code Online (Sandbox Code Playgroud)
我认为这里发生的事情是,当我为beds
数组分配一个新引用时,ngFor
删除了中的所有 html 代码,然后将为来自 observable 的更新数组中的对象创建新的 html 代码。
问题是更新到达时被删除的 html 代码似乎没有被垃圾收集。在一段时间内拍摄了多个堆快照后,我看到越来越多的分离 DOM 树,其中一些不断增加其保留大小。我在快照中没有看到任何以黄色突出显示的节点,但我有很多红色节点。
我不知道这是否与它有关,但我特别注意到以下代码中的很多红色HTMLInputElement
和HTMLImageElement
节点ngFor
:
<p>
<img draggable="false" [matTooltip]="translations?.Tooltip.O2" (click)="toggleO2(bed)" [src]="bed.additional_O2 ? medO2 : noO2">
</p>
<input class="jump-button" [matTooltip]="translations?.Tooltip.Jump2" type="image" src="../../assets/images/Jump_1-2.png" (click)="moveBed(bed, 2)">
Run Code Online (Sandbox Code Playgroud)
我真的不知道此时该怎么办。任何帮助深表感谢。谢谢!
我创建了一个动画,用于在图像发生变化时淡入/淡出图像src
。当我在图像之间快速切换时(在动画完成之前),出现以下错误:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
Previous value: 'src: http://localhost/wp-content/uploads/2018/11/billede1.jpg'.
Current value: 'src: http://localhost/wp-content/uploads/2018/11/billede2.jpg'
Run Code Online (Sandbox Code Playgroud)
但从视觉上看,并没有什么问题。动画工作正常并且显示正确的图像 - 即使我在它们之间快速切换并打印错误。但我想摆脱这个错误。关于我该如何做到这一点有什么想法吗?
动画片:
imageAnimation = trigger('imageAnimation', [
state('in', style({opacity: 1, })),
state('out', style({opacity: 0, })),
transition('in <=> out', [
animate('0.25s ease')
])
])
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="main-image-container" (mousemove)="displayBars()" [style.cursor]="mouseMovement ? 'default' : 'none'">
<img id="main-image" src="{{displayedImage}}" [@imageAnimation]="imgState" (@imageAnimation.done)="onImageAnimationDone($event)">
</div>
<div id="bottom-bar">
<div class="img-container" *ngFor="let img of gun.images">
<img src="{{img.thumbnail_image_url}}" [class.selected]="img.full_image_url == selectedImage" (click)="setSelectedImage(img.full_image_url)">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
成分:
onImageAnimationDone(event: any){
this.displayedImage = this.selectedImage; …
Run Code Online (Sandbox Code Playgroud) 在我的数据库中,我跟踪用户行驶的距离,并为每个人设置初始值 0。在我的代码中,我通过获取旧值并向其添加新距离来更新此值,然后保存该值。
首先,当我从数据库中检索 0 时,它以 Long 形式返回,这很好:
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Long previousDistance = (Long) dataSnapshot.child("distance").getValue();
userReference.child("distance").setValue(previousDistance.doubleValue()+distanceTravelled);
}
Run Code Online (Sandbox Code Playgroud)
问题是,现在,存储在数据库中的值是 Double,因此下次运行上述代码时,它将失败并显示ClassCastExcepiton
.
我可能可以用 if 语句解决这个问题,但最简单的解决方案是将最初的 0 存储为 Double 。但是,我无法做到这一点。我已经尝试过这两个:
myDatabase.child("users").child(lowerCaseUserName).child("distance").setValue(Double.valueOf(0.0));
myDatabase.child("users").child(lowerCaseUserName).child("distance").setValue(0.0);
Run Code Online (Sandbox Code Playgroud)
它们仍然存储为“0”并以 Long 形式返回。是否可以将零作为 Double 存储在数据库中?
我刚刚将angular更新到5.1.2版本。现在,我从标题中提到的模块导入中得到了此错误:
Module '"c:/pdws-view-v2/node_modules/@angular/platform-browser/animations"' has
no exported member 'BrowserAnimationsModule'.
Run Code Online (Sandbox Code Playgroud)
我的应用程序似乎运行良好,例如http调用成功。我想知道问题出在哪里(如果有的话)。
这里是进口:
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Run Code Online (Sandbox Code Playgroud)
谢谢。
angular ×6
firebase ×2
android ×1
get ×1
highcharts ×1
http ×1
java ×1
memory-leaks ×1
node.js ×1
protractor ×1
regex ×1
spring ×1
spring-boot ×1
testing ×1