服务:
import { Injectable } from "@angular/core";
import { Subject } from "rxjs";
@Injectable({
providedIn: "root"
})
export class AdminRoleLocalService {
public newRoleAdded = new Subject<boolean>();
constructor() {}
newRoleAddedEvent() {
this.newRoleAdded.next(true);
}
}
component-1:
submitAddRoleForm(addRoleForm: AddRoleData) {
this.isFetching = true;
this.roleService.addRoleData(addRoleForm).subscribe(
httpResponse => {
console.log(httpResponse);
this.isFetching = false;
this.roleLocalService.newRoleAddedEvent();
this.router.navigate(["/role-management"]);
},
errorMessage => {
console.log(errorMessage);
this.errorMessageContent(errorMessage);
}
);
}
component-2:
ngOnInit() {
this.roleLocalService.newRoleAdded.subscribe(flag => {
this.newRoleAddedFlag = flag;
});
}
我看到newRoleAddedFlag为undefined,因为我期望值为True。我无法找到我在哪里。请您帮助我。
尝试使用
public newRoleAdded = new behaviorSubject<boolean>(true);