Search code examples
javascriptangularjsangular-ngmodelangularjs-ng-model

How to convert 1 to true in markup for ng-model assignment?


This is my current ng-repeat code:

<li ng-repeat="tik in settingsModel.port_tickers">
    <input type="checkbox" ng-model="tik.alert" name="tik.ticker" value="tik.ticker">
    <p>{{ tik.ticker }}</p>
</li>

This is what a single tik object from settingsModel.port_tickers looks like:

{
    alert: 1,
    ticker: $TEST,
    user_id: 66
}

I'm getting either 1 or 0 back from the server, is there an easy way to filter this in the markup? Without having to use some kind of loop to convert 1s and 0s into true or false?


Solution

  • I believe you want to use ng-true-value="1" and ng-false-value="0" attributes. Check more at https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D