I have some JSON that has two arrays of objects, one for "articles" and one for "allCategories". My controller is getting the data and assigning the two arrays to their own $scope as seen here:
- $http.get(jsonFeed).success(function(response){
- // JSON Data
- $scope.articles = response.articles;
- $scope.allCategories = response.allCategories;
Then I iterate over the allCategories array to populate my select in the view:
- "newsArticleListing" ng-controller="articleListing">
- ="filter-form" method="get" name="Search" target="_top">
class="filter-form-holder">class="filter-form-item">- class="filter-form-label">Search by:
class="filter-form-item">class="filter-form-select-wrapper">- ="directorySelect angularFilter"
- ng-model="catSelect"
- ng-options="cat.name for cat in allCategories | orderBy: 'name'"
- ng-change="changeHandler()"
- style="height:59px; width:385px; border-radius:0px;" >
- > All News
- "border-radius: 5px;" class="text-search" ng-model="courseTextSearch" type="text" name="search" placeholder="Search all listings"/>
Then I iterate over the "articles" array and filter based off of the "catSelect" model, which is an object that contains { "name" : "somevalue", "filterValue" : "somevalue"} I am using "catSelect.filterValue"- class="container">
- class
- class
="news-list-item" dir-paginate="article in articles | orderBy: '-date' | filter : { categories : catSelect.filterValue || undefined } | filter: courseTextSearch | itemsPerPage:pageSize" current-page="pagination.current">class ="news-block" >"catChecker(catSelect.filterValue, article.categories)" class="news-block-holder is-blue">- class="news-block-taxonomy">{{ catSelect.name }}
- class="news-block-img-link" href="{{ article.link }}" target="_blank">
class="news-block-img" style="background-image: url('{{ article.thumbImage }}'); background-size: cover;">"{{ article.thumbImage }}" alt="{{ article.alt }}" />
class="news-block-body">- class="news-block-link" ng-show="article.title" href="{{ article.link }}" target="_blank">{{ article.title }}
- class="pagePagination">
"8" direction-links="true">
Everything works fine, accept when I try to add in the ability to set the selected value from a query string. I can't assign the property "catSelect.filterValue" from within my controller as below: (fyi.. I have predefined some links currently that are in the structure "?- year=someyear&topics=sometopic")
- if(window.location.href.includes('?'))
- {
- var queryString = window.location.href.split('?');
- var values = queryString[1].split('&');
- var topics = values[1].split('=');
- var topic = topics[1];
- console.log(topic);
- if(topics[0] == "topics"){
- $scope.catSelect.filterValue = topics[1];
- console.log($scope.catSelect.filterValue);
- }
- }
I thought because the model "catSelect" was two-way bound to the view I would have access to set the property of "$scope.catSelect.filterValue". What am I missing?
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Steve VoltmerPosted Apr 30, 2018, 7:36 AM
class="news-list">