我有一个简单的组件,它每隔几秒就调用一次REST api并收回一些JSON数据.我可以从我的日志语句和网络流量中看到返回的JSON数据正在发生变化,我的模型正在更新,但是视图没有变化.
我的组件看起来像:
import {Component, OnInit} from 'angular2/core';
import {RecentDetectionService} from '../services/recentdetection.service';
import {RecentDetection} from '../model/recentdetection';
import {Observable} from 'rxjs/Rx';
@Component({
selector: 'recent-detections',
templateUrl: '/app/components/recentdetection.template.html',
providers: [RecentDetectionService]
})
export class RecentDetectionComponent implements OnInit {
recentDetections: Array<RecentDetection>;
constructor(private recentDetectionService: RecentDetectionService) {
this.recentDetections = new Array<RecentDetection>();
}
getRecentDetections(): void {
this.recentDetectionService.getJsonFromApi()
.subscribe(recent => { this.recentDetections = recent;
console.log(this.recentDetections[0].macAddress) });
}
ngOnInit() {
this.getRecentDetections();
let timer = Observable.timer(2000, 5000);
timer.subscribe(() => this.getRecentDetections());
}
}
Run Code Online (Sandbox Code Playgroud)
我的观点看起来像:
<div class="panel panel-default">
<!-- Default panel contents --> …
Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用Date
TypeScript中的对象来格式化我想要的方式.
我有一个类Module
定义为:
export class Module {
constructor(public id: number, public name: string, public description: string,
public lastUpdated: Date, public owner: string) { }
getNiceLastUpdatedTime(): String {
let options: Intl.DateTimeFormatOptions = {
day: "numeric", month: "numeric", year: "numeric",
hour: "2-digit", minute: "2-digit"
};
return this.lastUpdated.toLocaleDateString("en-GB", options) + " " + this.lastUpdated.toLocaleTimeString("en-GB", options);
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用以下代码调用该方法时:
let date = new Date(1478708162000); // 09/11/2016 16:16pm (GMT)
let module = new Module(1, "Test", "description", date, "test owner");
console.log(module.getNiceLastUpdatedTime());
Run Code Online (Sandbox Code Playgroud)
我最终在控制台中打印了以下内容:
'9 …
Run Code Online (Sandbox Code Playgroud) 我目前有一个应用程序,它从用户那里获取起点和终点并向谷歌地图方向 API 发送请求,例如:https://maps.googleapis.com/maps/api/directions/xml?key=my_key8&origin=M460PU&destination=NN36NW&sensor=false&mode=driving&units=imperial&departure_time=1501752779
然后,我们显示给定路线的预计行程时间。用户询问我们是否可以添加直接指向 Google 地图的链接,以便他们可以在地图上看到路线并确保它看起来没问题。
我之前见过这样的问题:Link to Google Maps但这似乎是一个简单的 Google 地图搜索的解决方案,在我的例子中,我想从方向 API 中查看一条路线。
我试图弄清楚是否有一种方法可以从 Directions API 响应中获取数据并将其插入到用户可以点击的http://maps.google.com/maps URL 中。有没有人在这方面取得过成功?
我试图使用d3.js库和TypeScript绘制饼图.我有以下代码:
"use strict";
module Chart {
export class chart {
private chart: d3.Selection<string>;
private width: number;
private height: number;
private radius: number;
private donutWidth: number;
private dataset: { label: string, count: number }[];
private color: d3.scale.Ordinal<string, string>;
constructor(container: any) {
this.width = 360;
this.height = 360;
this.radius = Math.min(this.width, this.height) / 2;
this.donutWidth = 75;
this.dataset = [
{ label: 'Road', count: 5500 },
{ label: 'Bridge', count: 8800 },
{ label: 'Tunnel', count: 225 },
];
this.color = d3.scale.category10(); …
Run Code Online (Sandbox Code Playgroud) TestRepository ***extends*** JpaRespotiroy<Test,Long>
JpaRepository 是一个接口。为什么我们要扩展它而不是像我们在 Java 中所知道的那样实现它?据我所知,接口是实现的,而不是扩展的。
有人可以向我解释一下吗?
我在使用 Mockito 框架的测试中有以下代码来验证是否drawTextOnCanvas()
使用正确的参数调用了该方法。
// The two objects below are mocks. The rest of the objects used in
// the call to verify() are plain old java objects I've instantiated elsewhere.
BufferedImage testImage = Mockito.mock(BufferedImage.class);
Mockito.when(testImage.getHeight()).thenReturn(10);
Graphics mockGraphics = Mockito.mock(Graphics.class);
Mockito.when(mockGraphics.getFontMetrics(Matchers.any(Font.class)))
.thenReturn(Mockito.mock(FontMetrics.class));
Mockito.verify(drawingUtil).drawTextOnCanvas(
Matchers.eq(imageCategory.getWidth()),
Matchers.eq(mockGraphics),
Matchers.any(Font.class),
Matchers.eq(Arrays.asList("Test text")),
Matchers.eq(testImage.getHeight() + 10),
Matchers.any(FontMetrics.class),
Matchers.eq(10));
Run Code Online (Sandbox Code Playgroud)
但是它抛出以下异常:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
0 matchers expected, 4 recorded:
-> at com.test.package(ExampleTest.java:66)
-> at com.test.package(ExampleTest.java:67)
-> at com.test.package(ExampleTest.java:67)
-> at com.test.package(ExampleTest.java:68)
This exception …
Run Code Online (Sandbox Code Playgroud) 我设置了一个名为“state-changed”的 Azure 服务总线主题,并且它有一个名为“reverb”的订阅。我正在尝试设置一种方法来@JmsListener
订阅该主题,但收到错误:
2017-03-22 18:34:41.049 WARN 23356 --- [enerContainer-6] o.s.j.l.DefaultMessageListenerContainer : Setup of JMS message listener invoker failed for destination 'state-changed' - trying to recover. Cause: The messaging entity 'sb://[MySERVICEBUS].servicebus.windows.net/state-changed' could not be found. TrackingId:d2b442f79e0f44bdb449861ea57155ce_G44, SystemTracker:gateway6, Timestamp:3/22/2017 6:34:37 PM
javax.jms.JMSException: The messaging entity 'sb://[MySERVICEBUS].servicebus.windows.net/state-changed' could not be found. TrackingId:d2b442f79e0f44bdb449861ea57155ce_G44, SystemTracker:gateway6, Timestamp:3/22/2017 6:34:37 PM
at org.apache.qpid.amqp_1_0.jms.impl.TopicSubscriberImpl.createClientReceiver(TopicSubscriberImpl.java:111) ~[qpid-amqp-1-0-client-jms-0.32.jar:0.32]
at org.apache.qpid.amqp_1_0.jms.impl.MessageConsumerImpl.<init>(MessageConsumerImpl.java:129) ~[qpid-amqp-1-0-client-jms-0.32.jar:0.32]
at org.apache.qpid.amqp_1_0.jms.impl.TopicSubscriberImpl.<init>(TopicSubscriberImpl.java:46) ~[qpid-amqp-1-0-client-jms-0.32.jar:0.32]
at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createDurableSubscriber(SessionImpl.java:544) ~[qpid-amqp-1-0-client-jms-0.32.jar:0.32]
at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createDurableSubscriber(SessionImpl.java:59) ~[qpid-amqp-1-0-client-jms-0.32.jar:0.32]
at org.springframework.jms.listener.AbstractMessageListenerContainer.createConsumer(AbstractMessageListenerContainer.java:870) ~[spring-jms-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:215) ~[spring-jms-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1189) ~[spring-jms-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at …
Run Code Online (Sandbox Code Playgroud) java ×3
javascript ×2
typescript ×2
angular ×1
azure ×1
d3.js ×1
extends ×1
google-maps ×1
interface ×1
jpa ×1
mockito ×1
spring ×1
svg ×1