I want to set some default text inside the router-outlet until it is populated.
I have a parent component that will display the child route component within the router-outlet on that page.
There are 2 buttons that will populate the router-outlet with the child component when clicked. How can i place content inside the router outlet eg. 'Click an options to display the data' then once the button is clicked this message clears and the child component displays in the router outlet?
<div class="container pt-3">
<div class="clearfix">
<div class="btn btn-outline-success float-left"
routerLink="/unpaid/people">
View People
</div>
<div class="btn btn-outline-success float-right"
routerLink="/unpaid/bills">
View Bills
</div>
</div>
</div>
<router-outlet>Click an options to display the data</router-outlet>
EDIT here are my routes
path: 'unpaid', component: UnpaidBillsComponent,
children: [
{path: 'people', component: UnpaidPeopleComponent},
{path: 'bills', component: UnpaidBillListComponent}
]
There are various ways by which we can pass data from one component to another. Angular 7.2. 0 introduced a new way to pass data using State Object while navigating between routed components.
Default is "/" (the root path). The path-matching strategy, one of 'prefix' or 'full'. Default is 'prefix'. By default, the router checks URL elements from the left to see if the URL matches a given path and stops when there is a config match.
The Angular router-outlet Router-Outlet is an Angular directive from the router library that is used to insert the component matched by routes to be displayed on the screen.
What is an activated route? The Angular Docs define the ActivatedRoute as. A service that is provided to each route component that contains route specific information such as route parameters, static data, resolve data, global query params and the global fragment.
In Template:
<p *ngIf="showDefaultMessage">Click an options to display the data</p>
<router-outlet (activate)="toggleDefaultMessage(false)" (deactivate)="toggleDefaultMessage(true)"></router-outlet>
then in Component just toggle "showDefaultMessage" property:
private showDefaultMessage = true; // default state
toggleDefaultMessage(state: boolean) {
this.showDefaultMessage = state;
}
<div class="col-sm-10">
<router-outlet></router-outlet>
<a routerLink="/" routerLinkActive #rla="routerLinkActive"
[routerLinkActiveOptions]="{exact:true}">
<h5 *ngIf="rla.isActive" class="beauty">Click on any button to start!</h5>
</a>
</div>
https://angular.io/api/router/RouterLinkActive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With