I have tried to do my due diligence to figure this out but I am going no
where.
I have a search option where a user can choose search type (like userid,
first name, last name from drop down) and enter the corresponding value in
a text box (search val).
I want these values to persist when the user comes back to do the search
again.
Search option is provided as Router link.
I have created a service and included it in in apps.module.ts Providers. My
service is simple with searchType and searchVal properties with get and set
methods.
When I come back to search the second time, the previous values for search
type and search values are getting initialized.
I hope this is the correct forum to post this question and thanks in
advance for your help.
- Venkat.
*app-routing.module.ts (code snippet):*
export const routes: Routes = [
{path: 'searchUser', component: UserSearchComponent},
{path: 'updateUser', component: UserUpdateComponent}
];
*app-module.ts (code snippet):*
providers: [ UsersService ],
*app.component.html (code snippet):*
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Add user</a>
* <a class="dropdown-item" href="/searchUser">Search user</a>*
<a class="dropdown-item" href="/updateUser">Update user</a>
</div>
*user-search.component.ts (code snippet):*
@Injectable()
export class UserSearchComponent implements OnInit {
users: User[];
searchType: String; searchVal: String;
constructor(private usersService: UsersService) {
}
ngOnInit() {
alert("Search component.OnInit");
alert("Service:" + this.usersService.getSearchType());
alert("local:" + this.searchType);
this.searchType = this.usersService.getSearchType();
this.searchVal = this.usersService.getSearchVal();
}
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.