我在Angular 2中使用Jhipster 4,并且需要在我的项目中使用3rd party lib,但是该库不在npm上,并且没有.d.ts文件。我需要直接包括js。在vendor.ts内部导入适用于通过npm安装的库,但不适用于我的js,如何在项目中使用此文件?
我有一个具有两个不同函数的服务,它们获取由 BehaviorSubject 监视的数组中的 itens 数。
private itemsInCartSubject: BehaviorSubject<any[]> = new BehaviorSubject([]);
private itemsInCart: any[] = [];
private packetsInCartSubject: BehaviorSubject<Pacote[]> = new BehaviorSubject([]);
private packetsInCart: Pacote[] = [];
public getTotalItens(): Observable<number> {
return this.itemsInCartSubject.map((items: any[]) => {
return items.reduce((prev, curr: any) => {
return prev + Number(curr.qtd);
}, 0);
});
};
public getTotalPacotes(): Observable<number> {
return this.packetsInCartSubject.map((items: any[]) => {
return items.reduce((prev, curr: any) => {
return prev + Number(1);
}, 0);
});
};
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我有两种方法来获取这些数字:
public countItens(): Observable<number> {
return this.cartService.getTotalItens(); …Run Code Online (Sandbox Code Playgroud) 在 Spring Boot 中使用 websockets 时,我见过使用以下示例:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic/");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/greeting");;
}
}
Run Code Online (Sandbox Code Playgroud)
指定 config.setApplicationDestinationPrefixes("/app") 并在控制器中使用 @MessageMapping 注释。
而且我还看到了仅使用 enableSimpleBroker() 并在控制器中使用 @SubscribeMapping 的示例。
据我了解,@MessageMapping 负责将收到的消息路由到正确的方法。并且只有当目的地包含在 setApplicationDestinationPrefixes 中声明的前缀之一时,才会触发带有此注释的方法。
但是@SubscribeMapping 也将消息路由到正确的方法,我们不需要在配置类中调用 setApplicationDestinationPrefixes()。
有什么不同?
angular ×2
javascript ×1
jhipster ×1
observable ×1
spring-boot ×1
stomp ×1
typescript ×1
websocket ×1