TechQA.

        Angular: How to filter out by style?

        136 views Asked by AmazingDayToday At 2017-06-08T20:43:42+00:00 08 June 2017 at 20:43 2025-12-21T13:09:15+00:00

        I am new to Angular, so this might seem easy. This is the HTML code:

        <div>
            Has Time: <input type="checkbox" ng-model="people_filter">
        </div>
        <ul style="list-style: none;">
            <li ng-repeat="human in people | orderBy:'name' | filter:people_filter ">
                <a href="#!/" ng-style="set_availability(human)">
                    {{human.name}}
                </a>
            </li>
        </ul>
        

        JS code:

        $scope.set_availability = function(human) {
                if (the human has time) {
                    return {
                            color: 'blue'
                    };
                }
        
                return {
                    color: 'red'
                };
            };
        

        When I inspect element:

        <a href="#!/" ng-style="set_availability(human)" class="ng-binding" style="color: blue;">
            John Lennon
        </a>
        

        I have a checkbox with ng-model="people_filter".

        If checked, I want it to filter out people who are available.
        If unchecked, I want to list all of the people.

        The availability is reflected in ng-style="blue" (if yes) or ng-style="red" (if no). And it is working, I am able to see style="color:blue;" or style="color:red;".

        Is there a quick fix for this?

        angularjs ng-style ng-filter
        Original Q&A
        1

        There are 1 answers

        6
        AudioBubble AudioBubble On 2017-06-08T21:12:34+00:00 08 June 2017 at 21:12

        I think you want to change the color of the style based on the output of the function call. Please check this out.

        $availableHuman = [];
        $scope.set_availability = function(human) {
                    if (human.time) {                    
                        availableHuman.push(human); 
                        return {
                     "color:"+blue+";
                        };
                    } 
        
                    return {
                         "color:"+red+";
                    };
                };
        
        
        
        
         <div class="list" ng-repeat="human in availableHuman">
          {{ human }}
        </div>
        

        Related Questions in ANGULARJS

        • How to automatically change path in angular when scrolling
        • Error two clicks to be able to login Angular 16
        • Passing an array of objects through the $http.post method in angular JS does not work
        • Understanding how to apply Angular Signals from beginning on an existing service
        • provider duplicate while compiling a Cordova application for the Android platform
        • How can I use angularjs $parse service in Angular?
        • Width of custom headers in ag-grid (angular) doesn't match with column's width
        • Issues with Katex/ngx-markdown Rendering in Angular 16
        • How to make Angular SSR wait for async operations to finish that are initiated in ngOnInit?
        • I want to install @angular/google-maps npm Package in angular 16.2.12 but "npm install @angular/google-maps" this is not working/ tell me other query
        • Angular 17 standalone application integrate CKEditor 5 -- Error: window is not defined
        • Why is $scope >= 0 showing true in interpolation while empty in controller?
        • The XMLHttpRequest compatibility library was not found
        • Making Gantt Chart Column Labels More Readable
        • Pass key-value pairs of object as individual arguments to component in Angular

        Related Questions in NG-STYLE

        • How to change color of text in a table cell based on value in Angular?
        • Programmatically change mouse cursor using Angular
        • i want to control CSS of .cylinder::after dynamically in html, how to do this?
        • NgStyle works in webApp but not in Capacitor compiled android app
        • ng-style not working in angularjs ionicapp
        • Can Angular ngStyle take more than one function? What's the workaround if not?
        • ngStyle to set background color of whole web page
        • Angular apply css dinamically without knowing the properties
        • Angular - How to include button event?
        • How to change div background image in ionic
        • Hiding Secondary scrollbar with css and [ngStyle] question
        • Applying ngStyle to all p tags within an html page
        • How to change background color in an NgFor input if the value changed?
        • ngStyle for specific condition
        • Apply CSS style to angular componet from within the component

        Related Questions in NG-FILTER

        • Optimise ng-bind directive in angularjs
        • AngularJs ng-repeat Filter By Limit Conditionally
        • seach filter inside a parent ng-repeat not working
        • angularjs ng-repeat ng-options custom filter
        • Sort IP Address AngularJS
        • Trying to Display Results between Two Dates Using AngularJS
        • filter through array of objects in ng-repeat angular.js
        • AngularJS: Apply search filter only to first child of ng-repeat
        • Angular JS Controller with Filter For JSON Array Of Objects
        • Displaying icon using ng-if on nested array
        • How can I custom sort the contentful response on the frontend of my angular app
        • ngFilter equals with 2 var in angular
        • Angular: How to filter out by style?
        • Search in Ng-Repeat without hiding anything
        • Changing the values of ng-repeat based on the ng-change function

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?

        Popular Tags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
        • Privacy
        • Terms
        • Cookies
        • Homegardensmart
        • Math
        • Aftereffectstemplates