我想搜索具有值的 Enum,并获取它的键。这就是我现在所拥有的:
  private find(value: MyEnum): string {
    for (const key in MyEnum) {
      if (value === MyEnum[key]) {
        return key;
      }
    }
    return null;
  }
Run Code Online (Sandbox Code Playgroud)
我们不能让它更简单吗?这似乎是一个过度工程..
实际上我想要的只是 Java 中的 value.name()。
编辑:MyEnum 是这样的:
export enum MyEnum {
  YES = 'x',
  NO = 'y'
}
Run Code Online (Sandbox Code Playgroud) 我有一个自定义的标签实现,在其中我用一些ngIf指令显示标签内容,如下所示:
<tab1 *ngIf="condition === 1"></tab1>
<tab2 *ngIf="condition === 2"></tab2>
Run Code Online (Sandbox Code Playgroud)
制表符具有自己的形式,某些内容仅应初始化一次,不再需要初始化。在我当前的实现中,每次我更改条件然后更改选项卡时,都会再次初始化组件tab1和tab2。
我们是否还有其他ngIf替代项(例如可能是旧的ng-show),它不会再次初始化组件,而只是淡出UI上的新内容。否则,我必须使用CSS(不显示任何内容)来做。
我们有一些按钮,用css设置样式,并有一些像这样的图标:
此按钮具有默认的轮廓属性,因此每次我们点击它时,它都有一个轮廓(镀铬蓝色):
为了摆脱它,我们当然可以覆盖这个属性,如:
outline: none
Run Code Online (Sandbox Code Playgroud)
但是当我们选中并触及此按钮时,它也没有任何轮廓,这对于可访问性来说是一种不好的做法.
我们能否实现这一点,以便只有当我们使用标签来显示此按钮时才显示此轮廓,但是当我们点击它时却不会出现?
正如信息:我们也有一些一个似乎在视觉上就这样的标签,并用标签,我们有确切的这种行为,我们希望,轮廓似乎只有当我们到那个链接选项卡,但不能点击.我们只想与按钮标签具有完全相同的行为.
我有这个案例:
我现在有这样的事情,而没有正确使用 RxJS:
this.service.readArray().subscribe((array: Object[]) => {
  if (array.length > 0) {
    array.forEach((item, index) => {
      this.service2.readItem(item.id)
        .subscribe(details => {
          item.details = details;
          // manually finally logic
          if (index === array.length - 1) { // if the last iteration
            ...
          }
        }, (response: HttpErrorResponse) => {
            ...
          // manually finally logic also for error part
          if (index === array.length - 1) { // if the last iteration
          ... 
          }
        });
    });
  } else {
    ... logic for …Run Code Online (Sandbox Code Playgroud) 我有一个服务调用,它的响应缓存在我的 Angular 服务中,如下所示:
public cacheMyServiceResponse(): Observable<any> {
  return this.appConfig.getEndpoint('myService')
    .pipe(
      switchMap((endpoint: Endpoint) => this.http.get(endpoint.toUrl())),
      tap((body: any) => {
        if (body) { //  this endpoint can also return a 204 (No Content), where body is null
          this.cache = body.myData;
        }
      }),
      take(1),
      catchError(error => {
        this.errorService.trackError(error.status);
        return of(true);
      })
    );
}
Run Code Online (Sandbox Code Playgroud)
所以我的 http.get 调用的响应将被缓存在这里,在一个名为“缓存”的全局变量中。
问题是,这个调用可能真的响应很晚,所以我们想在页面加载时(初始化时)立即调用这个端点。但是实际的响应,或者我们的调用是否完成(成功或错误),我们只在用户点击按钮时才需要这些信息。当然,在按钮点击的那一刻,响应可能还没有,并且在这种情况我想等一下。(所以我需要的不仅仅是一个简单的布尔标志)
所以我想像这样在 ngOnInit 中初始化这个调用:
ngOnInit() {
    this.myService.cacheMyServiceResponse().subscribe();
}
Run Code Online (Sandbox Code Playgroud)
但是在其他地方,我需要知道它是否已经完成了调用,而无需两次触发我的 http 调用。
onClick() {
    this.myService.cacheMyServiceResponse().subscribe(() => {
       // call is finished..
    });
}
Run Code Online (Sandbox Code Playgroud)
目前该服务将被调用两次。我怎样才能做到这一点?
PS:我没有故意进行错误处理,我只需要知道服务调用是否完成。
我有两个Spring项目,Backend和Frontend.后端的升级没有问题(Spring 4.1.2.RELEASE).虽然部署前端我有这个例外:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [acn.spring.config.AppConfig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:489)
....
Caused by: 
java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]
Run Code Online (Sandbox Code Playgroud)
这是Frontend的WebAppInitializer:
@Configuration
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[] { AppConfig.class };
    }
    .....
Run Code Online (Sandbox Code Playgroud)
Appconfig位于后端项目中,如下所示:
@Import(DataConfig.class)
@Configuration
public class AppConfig {
   ...
}
Run Code Online (Sandbox Code Playgroud)
缺少的属性文件在DataConfig中使用,在此处导入:
@PropertySource("jdbc.properties")
@Configuration
public class DataConfig {
   ...
}
Run Code Online (Sandbox Code Playgroud)
为什么找不到属性文件?
编辑:后端的Jar结构:
我们有一个评级组件:
uib-rating(ng-init="average = xxxx", ng-model="average", max="5", readonly="true")
Run Code Online (Sandbox Code Playgroud)
由于ng-model在这里使用局部变量,我们有意识地以一种方式绑定该组件.但问题在于readonly属性.
这在我们的本地机器上运行良好.但是当我们在服务器(linux astra)上部署它时,星星仍然活跃.什么可能导致这个问题?(我们在服务器和本地机器上使用相同的角度组件版本)
我用 Angular 写了一个抽屉动画。看起来像这样:
  transition(':enter', [
    style({height: '0', opacity: 0}),
    group([
      animate(300, style({height: '*'})),
      animate('300ms ease-in-out', style({'opacity': '1'}))
    ])
  ]) ,
  transition(':leave', [
    style({height: '*', opacity: 1}),
    group([
      animate(300, style({height: 0})),
      animate('300ms ease-in-out', style({'opacity': '0'}))
    ] )
    ])
Run Code Online (Sandbox Code Playgroud)
我的主 div(此动画粘贴的位置)也有一个填充(所有 4 个方向均为 20 像素)。
问题:只要 div 可见(通过 *ngIf),我的高度动画就会开始工作。但是元素的填充立即存在.. 其余的将被动画化。所以它在动画开始时有一个闪烁的效果。
我怎样才能得到填充动画?或者我应该改变什么?
我有 2 个文档,主题和评论。每个主题都有很多评论,文档如下所示:
@Document
public class Topic {
    @Id
    private String id;
    @Indexed(unique = true)
    @NotBlank
    private String title;
}
@Document
public class Comment {
    @NotBlank
    private String text;
    @Indexed
    @NotBlank
    private String topic;  // id of topic
    @CreatedDate
    @Indexed
    private LocalDateTime createdDate;
}
Run Code Online (Sandbox Code Playgroud)
所以我实际上将 Topic 的 id 引用保存在评论中。
这是我的聚合场景:列出今天收到最多评论的主题。所以三件事:
这是到目前为止的代码:
MatchOperation filterCreatedDate = match(Criteria.where("createdDate").gte(today.atStartOfDay()).lt(today.plusDays(1).atStartOfDay()));
GroupOperation groupByTopic = group("topic").count().as("todaysCommentsCount");
SortOperation sortByTodaysCommentsCount = sort(Sort.Direction.DESC, "todaysCommentsCount");
Aggregation aggregation = newAggregation(filterCreatedDate, groupByTopic, sortByTodaysCommentsCount);
AggregationResults<TopTopic> result = mongoTemplate.aggregate(aggregation, …Run Code Online (Sandbox Code Playgroud) angular ×4
css ×2
rxjs ×2
angular-ui ×1
angular6 ×1
angularjs ×1
css3 ×1
html ×1
html5 ×1
java ×1
maven ×1
mongodb ×1
spring ×1
spring-data ×1
spring-mvc ×1
typescript ×1