Skip to content
Loading
Set a property on an Angular model from the controller       
  •   
  • 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"
    1. class="container">    
    2.         class="news-list">    
    3.         class="news-list-item" dir-paginate="article in articles | orderBy: '-date' | filter : { categories : catSelect.filterValue || undefined } | filter: courseTextSearch | itemsPerPage:pageSize" current-page="pagination.current">    
    4.         class="news-block" >    
    5.             "catChecker(catSelect.filterValue, article.categories)" class="news-block-holder is-blue">    
    6.             class="news-block-taxonomy">{{ catSelect.name }}    
    7.             
        
  •                 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 "?
    1. year=someyear&topics=sometopic")  
    2.    
    3. if(window.location.href.includes('?'))    
    4. {    
    5.     var queryString = window.location.href.split('?');    
    6.     var values = queryString[1].split('&');    
    7.     var topics = values[1].split('=');    
    8.     var topic = topics[1];    
    9.     console.log(topic);    
    10.     if(topics[0] == "topics"){   
    11.         $scope.catSelect.filterValue = topics[1];    
    12.         console.log($scope.catSelect.filterValue);    
    13.     }    
    14. }  
    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.