я создаю небольшое приложение, в котором я хочу, чтобы при каждом запросе на сервер я получал ActivityIndicator.
Итак, в моей службе пользовательского интерфейса у меня есть Тема, и я слушаю ее в своем ActivityIndicatorComponent.Результат: он начинает "занято", но не останавливается, даже если переменная в атрибуте индикатора "занято" имеет значение false.
То есть идентификатор как-то "не обновляется" после однократной инициализации?
My UIService
@Injectable({ providedIn: 'root'})
export class UiService {
private _drawerState= new BehaviorSubject<void>(null);
isLoading = new Subject<boolean>();
get drawerState() {
return this._drawerState.asObservable();
}
toggleDrawer() {
this._drawerState.next(null);
}
setIsLoading(value: boolean) {
this.isLoading.next(value);
}
}
My Socket Service, который вызывает метод в Ui Service:
export class SocketioService {
socket;
currentRoom: ChatRoom;
message_receiver = new Subject<Message>();
room_receiver = new Subject<ChatRoom>();
constructor(private router: RouterExtensions, private ui: UiService) {
this.socket = SocketIO.connect("http://localhost:3000");
console.log("SOCKET: " + this.socket);
this.socket.on("chat room", (room) => this.onReceivingChatRoom(room));
}
onRequestRoomlist(data) {
this.ui.setIsLoading(true);
this.socket.emit("request rooms", data);
}
onReceivingChatRoom(room) {
this.ui.setIsLoading(false);
console.log("Received Chat Room");
this.room_receiver.next(new ChatRoom(room.name, room.description, room.image, room.protection));
}
}
И, наконец, я слушаю тему в моем ActivityIndicatorComponent:
export class ActivityIndicatorComponent implements OnInit {
isLoading: boolean;
constructor(private ui: UiService) { }
ngOnInit() {
this.ui.isLoading.subscribe(
(value: boolean) => {
this.isLoading = value;
}
)
}
}
Вот XML-код компонента ActivityIndicatorComponent
<ActivityIndicator #indicator row="1" col="1" width="50" height="50" busy="{{isLoading}}" color="#6495ed"></ActivityIndicator>