@Component({
selector: 'app-onb',
standalone: true,
imports: [],
templateUrl: './onb.component.html',
})
export class OnbComponent implements OnDestroy {
receivedData: any;
onbResponse = signal<any[]>([]);
private sseSubscription?: Subscription;
constructor(
private router: Router,
private onbService: OnbService,
) {
const navigation = this.router.getCurrentNavigation();
this.sseSubscription = this.onbService.run().subscribe({
next: (data) => {
this.onbResponse.update((values) => {
if (!values) {
return [data];
}
return [...values, data];
});
alert(this.onbResponse()); //this is updated correctly
},
error: (error) => {
console.error('Received SSE error:', error);
},
});
}
}
@if (onbResponse().length == 0) {
<p>loading</p>
} @else {
{{onbResponse()}}strong text
}
我正在使用服务和 sse 接收一些数据。 所有这些都有效,因为代码被触发并弹出警报。
使用信号和@if @else的条件渲染不起作用。
违反直觉,但这将导致“B”。
const test: any[] = []
if(!test){
console.log("A")
}else{
console.log("B")
}
我想你想放弃否定。