My attempt to utilize a shared service in one of my components has been successful when used with the app's root component. However, I encountered an error when trying to implement it on another module or dashboard.
https://i.sstatic.net/x3rRv.png
shared/authorize.service.ts
@Injectable()
export class AuthorizationService {
isDoingSomething() {
return "Some Boolean value";
}
}
dashboard/header/header.component.ts
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
export class HeaderComponent {
constructor(private _auth: AuthorizeService,
private _router: Router) { }
}
dashboard/header/header.component.html
<mat-toolbar color="primary" role="heading">
<div fxFlex fxLayout fxLayoutAlign="flex-end">
<ul fxLayout fxLayoutGap="10px" class="navigation-items">
<li routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
<a routerLink="/home">Home</a>
</li>
<li routerLinkActive="active">
<a *ngIf="_auth.isDoingSomething()" routerLink="/docall">Rest Call</a>
</li>
</ul>
</div>
</mat-toolbar>
**HeaderComponent.html:6 ERROR TypeError:** Cannot read property 'isDoingSomething' of undefined at Object.eval [as updateDirectives] (HeaderComponent.html:6) at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911) at checkAndUpdateView (core.js:23307)