如何防止在ngOninit完成执行之前调用ngAfterViewInit()

时间:2019-02-15 08:31:24

标签: angular7

我用角材料将桌子分类为角7。因此,发生了什么事,我正在从@MessageEndpoint @Log public class MessageFromEvent { private final EntityManagerFactory entityManagerFactory; private final JpaTransactionManager transactionManager; @Autowired public MessageFromEvent(EntityManagerFactory entityManagerFactory, JpaTransactionManager transactionManager) { this.entityManagerFactory = entityManagerFactory; this.transactionManager = transactionManager; } @Bean @InboundChannelAdapter(channel = "selectEventChannel", poller = @Poller(fixedDelay = "10000")) public MessageSource<?> selectEvent() { log.info("STEP 1: Getting data form EventStore table"); return new JpaPollingChannelAdapter(selectEventExecutor()); } @Bean public JpaExecutor selectEventExecutor() { JpaExecutor executor = new JpaExecutor(this.entityManagerFactory); executor.setJpaQuery("select event from Event event where event.eventStatus = 0"); executor.setUsePayloadAsParameterSource(true); executor.setEntityClass(Event.class); return executor; } @Bean @ServiceActivator(inputChannel = "selectEventChannel") public MessageHandler updateEventStatus(JpaExecutor updateEventExecutor) { log.info("STEP 2: Updating event status"); JpaOutboundGateway gateway = new JpaOutboundGateway(updateEventExecutor); gateway.setGatewayType(OutboundGatewayType.UPDATING); MatchAlwaysTransactionAttributeSource attributeSource = new MatchAlwaysTransactionAttributeSource(); attributeSource.setTransactionAttribute(new DefaultTransactionAttribute()); TransactionInterceptor interceptor = new TransactionInterceptor(transactionManager, attributeSource); gateway.setAdviceChain(singletonList(interceptor)); return gateway; } @Bean public JpaExecutor updateEventExecutor() { JpaExecutor executor = new JpaExecutor(this.entityManagerFactory); executor.setJpaQuery("update Event E set E.eventStatus = 1 where E.eventStoreId in (:eventStoreId)"); executor.setJpaParameters(Collections.singletonList(new JpaParameter("Event.eventStoreId", null, "payload"))); executor.setUsePayloadAsParameterSource(true); executor.setEntityClass(Event.class); return executor; } } 方法调用剩余服务。然后在ngAfterViewInit中,我正在编写以下代码进行排序。

ngOnInit()

但是发生的事情是它不是在等待其余服务完成执行,而是在ngAfterViewInit() { this.dataSource.sort = this.sort; } 完成执行之前调用ngAfterViewInit

由于上述原因,在我显示表格的网页中未进行排序。

1 个答案:

答案 0 :(得分:1)

Saroj,您可以为此使用 setTimeOut 。如果您提供更多详细信息,我们可以采用其他方式。

ngAfterViewInit() {
   setTimeout(() => {
          this.dataSource.sort = this.sort;
   }, 500);
}