Solved

Preserve state of  dropdown using tabs in AngularJS

Posted on 2014-01-21
3
1,179 Views
Last Modified: 2014-02-26
Hi Experts,

I am developing single page application using angularjs,html5,bootstrap and ASP.net MVC.The landing page has 3 tabs and common Save for all the tabs and in one of the tab I have a dropdown and the code is  similar to below code in Angular.First time when the page loads the value for the dropdown should be "None" and if user selects a value  in the dropdown  and navigates to other tabs and return backs to dropdown and should see last selected option ie. I should maintain the previous state of the dropdown while navigating the tabs.

In the below example if I select  option "Yellow" and then navigate to other tabs and back to original tab it should retain "Yellow" option. That means I should only show "None" at the first time when user Login.

In the code , I am just initializing the dropdown value  to "None" in the controller at all times , but I need this to be "None" only first time.How can I achieve this using angularjs?


 $scope.state = $scope.status[0]; //This will always set tDropdown to None 

Open in new window


demo
0
Comment
Question by:ksd123
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 39796766
Hi,

I think you need to check $scope.state before setting it:
    if (typeof $scope.state === 'undefined') {
            $scope.state = $scope.status[0];
    }

Open in new window


Giannis
0
 

Author Comment

by:ksd123
ID: 39799321
I tried above code and it's  not working,when I switch between tabs , it always select "None" option in the dropdown selection.
0
 

Author Closing Comment

by:ksd123
ID: 39888346
Thank you.  Actually there is typo in my code and later I  figure it out and  now the above code is working fine for my issue.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now