I want to assign priceFilter a true/false based on condition in a function

Bhawneet Singh

Image consists of html part $scope.options = ['Low Price To High', 'High Price To Low'];

    $scope.selectPriceFilter = function (priceFilter) {

             if ($scope.options === 'Low Price To High') {
            $scope.priceFilter = false;
        }      

         else if ($scope.options === 'High Price To Low') {
             $scope.priceFilter = true;
        }
    }
Josito

I'm not sure what you want. I think you want to assign true or false to priceFilter model depending on the option selected.

Your error is in the if comparation. Your model value is in priceFilter not in $scope.options.

Here you have some solutions.

Solution 1.

$scope.selectPriceFilter = function (priceFilter) {
  $scope.priceFilter = (priceFilter === 'High Price To Low');

   //Is the same than:
   /*if (priceFilter === 'Low Price To High') {
        $scope.priceFilter = false;
    }      

     else if (priceFilter === 'High Price To Low') {
         $scope.priceFilter = true;
    } */
}

Solution 2. I think this solution is better.

<select class="slect select-styled" ng-model="priceFilter" ng-options="option.value as option.key for option in options">
  <option value="">-- Price --</option>
</select>

Controller

function TodoCtrl($scope) {
 $scope.options = [{key:'Low Price To High',value: false}, {key: 'High Price To Low', value: true}];
}

I hope this helps you

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can I assign function based on the condition in jquery?

From Dev

I want to remove xml tag using XSLT based on condition

From Dev

Assign a value based on if condition in Scala

From Dev

Assign Ranks to records based on condition

From Dev

Assign value based on a condition in javascript

From Dev

I want update from one table to another table based on true or false condition

From Dev

MySQL - I want my table JOIN to return a single row based on a condition

From Dev

Assign value to group based on condition in column

From Dev

Assign values in Pandas series based on condition?

From Dev

Assign True/False condition based on existing columns

From Dev

Assign values in Pandas series based on condition?

From Dev

How to assign values to a column of a dataframe based on a condition?

From Dev

How to assign probabilities based on certain condition?

From Dev

What if I want to assign a property to itself?

From Dev

I have a JQuery function that sets active based on hover, I want to automate this to avoid duplication of effort

From Dev

Want to create new data frames in R by subsetting a data frame in a loop and assign each data frame name based on i value

From Dev

I want first and second inserted value with condition

From Dev

I want to resize image by scrolling; however, my function seems wrong. I can't use if condition properly

From Dev

I want ignore the failure of keyword based on condition and continue to next keyword to already existing huge set of test cases and suits

From Dev

function not returning value I want

From Dev

Can I assign a function to a variable?

From Dev

Why can't I assign this DataGridViewComboBoxCell to the cell I want?

From Dev

R function to assign value based on multiple columns

From Dev

How to assign varaible in ng-model on input based on condition

From Dev

Assign value to variable based on condition (value of other variable) in PLSQL

From Dev

Assign value to a pandas dataframe column based on string condition

From Dev

How to assign unique values to groups of rows in a pandas dataframe based on a condition?

From Dev

How to assign a value to a column for a subset of dataframe based on a condition in Pandas?

From Dev

Assign value to a column from another column based on condition

Related Related

  1. 1

    Can I assign function based on the condition in jquery?

  2. 2

    I want to remove xml tag using XSLT based on condition

  3. 3

    Assign a value based on if condition in Scala

  4. 4

    Assign Ranks to records based on condition

  5. 5

    Assign value based on a condition in javascript

  6. 6

    I want update from one table to another table based on true or false condition

  7. 7

    MySQL - I want my table JOIN to return a single row based on a condition

  8. 8

    Assign value to group based on condition in column

  9. 9

    Assign values in Pandas series based on condition?

  10. 10

    Assign True/False condition based on existing columns

  11. 11

    Assign values in Pandas series based on condition?

  12. 12

    How to assign values to a column of a dataframe based on a condition?

  13. 13

    How to assign probabilities based on certain condition?

  14. 14

    What if I want to assign a property to itself?

  15. 15

    I have a JQuery function that sets active based on hover, I want to automate this to avoid duplication of effort

  16. 16

    Want to create new data frames in R by subsetting a data frame in a loop and assign each data frame name based on i value

  17. 17

    I want first and second inserted value with condition

  18. 18

    I want to resize image by scrolling; however, my function seems wrong. I can't use if condition properly

  19. 19

    I want ignore the failure of keyword based on condition and continue to next keyword to already existing huge set of test cases and suits

  20. 20

    function not returning value I want

  21. 21

    Can I assign a function to a variable?

  22. 22

    Why can't I assign this DataGridViewComboBoxCell to the cell I want?

  23. 23

    R function to assign value based on multiple columns

  24. 24

    How to assign varaible in ng-model on input based on condition

  25. 25

    Assign value to variable based on condition (value of other variable) in PLSQL

  26. 26

    Assign value to a pandas dataframe column based on string condition

  27. 27

    How to assign unique values to groups of rows in a pandas dataframe based on a condition?

  28. 28

    How to assign a value to a column for a subset of dataframe based on a condition in Pandas?

  29. 29

    Assign value to a column from another column based on condition

HotTag

Archive