Hey, I'm a newcomer to Angular 7 and Ionic 4. How can I manage variables on the dashboard page from another page?
I attempted a simple logic in my application by controlling tbFor with the setToolbar function at dashboard.page.ts from landing-in.page.ts, but it was unsuccessful and resulted in an error:
(ERROR Error: Uncaught (in promise): Error: StaticInjectorError (AppModule) [LandingInPage -> DashboardPage] :).
However, this issue seemed to resolve when I imported dashboard.page.ts into app.module.ts and included it in providers. Strangely, when I logged the setToolbar results as "true," upon page load, the value of the variable tbFor remained "false".
Here's an example snippet from dashboard.page.ts for reference:
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { MenuController } from "@ionic/angular";
import { AuthService } from "../services/auth/auth.service";
@Component({
selector: "app-dashboard",
templateUrl: "./dashboard.page.html",
styleUrls: ["./dashboard.page.scss"]
})
export class DashboardPage implements OnInit {
tbFor = {
divCS: false,
divGA: false,
divTC: false
};
constructor(
public router: Router,
public menu: MenuController,
private authService: AuthService
) {
this.initializeApp();
}
initializeApp() {
this.menu.enable(true, "sideMenu");
}
setToolbar(div) {
if (div == "CS") {
this.tbFor.divCS = true;
} else if (div == "GA") {
this.tbFor.divGA = true;
} else if (div == "TC") {
//Ignores
this.tbFor.divTC = false;
}
}
clearToolbar() {
this.tbFor.divCS = false;
this.tbFor.divGA = false;
this.tbFor.divTC = false;
}
}
...