0

I've used angular plenty of times, but can't seem to spot the issue I'm getting:

I pass through an ID like so as a clickable link within a repeater:

<td data-title="'Company Name'" sortable="'CompanyName'"><a ui-sref="Locations({company_id: row.CompanyID})">{{row.CompanyName}}</a> </td>

The value is correctly passed through and received by the relevant controller I use a query string service to get the relevant filters. The console.log correctly shows the correct value. However, it is not selecting the relevant value within the select dropdown:

angular.module('app').controller("LocationsController", ['$timeout',  
'$scope', '$http', 'QueryStringService', 'NgTableParams', '$location', 
function ($timeout, $scope, $http, QueryStringService, NgTableParams, 
$location) {
var default_filters = { location_name: "", address_1: "", company_id: "" };
$scope.filterBy = QueryStringService.getFilters(jQuery.extend(true, {}, default_filters));

console.log($scope.filterBy.company_id);
}


// Displayed on relevant view
<select ng-model="filterBy.company_id" ng-options="option.CompanyID as option.CompanyName for option in companies" class="form-control form-control-query">
    <option value="">All</option>
</select>

Can anyone notice anything?

2
  • Is the select in another page of your app? Commented May 4, 2017 at 12:46
  • Yes it is, the select brings all correct values it just doesn't select the correct choice according to the value brought through. Commented May 4, 2017 at 12:49

1 Answer 1

1

I think you are facing a controller scope issue: You are setting a variable in a controller instance, and trying to get it from another instance.

The fact is that a controller is instancied for each page, even if it is the same controller name (that may be confusing).

You should use a service to store this variable (for example your QueryStringService), and access it from your other page.


Here is a JSFiddle demo.

Sign up to request clarification or add additional context in comments.

1 Comment

I've used this way of setting values before and it's always worked up until now...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.