0

I have a simple filter that puts one of two statements, based on if a input from SQL is true

    app.filter('yesNo', function() {
      return function(input) {
          return (input == '1') ? 'Skal tjekkes!' : 'Alt OK';
      }
  });

And then should change a menu item based on that;

    <li role="presentation"><a href="#" data-ng-click="statusFilter = 'Ny ordre'">New Orders
      <div ng-if="input == '1' | outdated">
          <p>Needs to be checked: {{(orders | filter:{status:'ny ordre', outdated: '1'}).length}}</p>
            </div>
            <div ng-if="!input == '1' | outdated">Shows regardless</div>

      </a></li>

I am missing something, just no idea what. :(

5
  • 1
    There is a ' too much in ng-if="!input == '1'' | outdated" Commented May 24, 2016 at 13:54
  • Thanks, missed that, but Im afraid its just showing both items Commented May 24, 2016 at 13:56
  • If I put <div ng-if=!"input == '1' | outdated">Shows regardless</div> It will stop showing it, but it will still show the other even if I know that is 0 Commented May 24, 2016 at 14:05
  • Why would you put ! outside the quotation marks? That's not even valid SGML. My suggestion was to use input != '1'. Commented May 24, 2016 at 14:16
  • Yes ok, I forgot to mention I tried that as well, and it just shows regardless :/ Commented May 24, 2016 at 14:18

1 Answer 1

1

You have an example here for how to use a custom filter function: http://jsfiddle.net/alexdumitrescu/zv6cf7nq/

var myApp = angular.module('myApp', [])
  .filter('myfilter', function() {
    return function(orders) {
      return orders.filter(function(order) {
        return order.outdated == '1';
      })
    }
  });

function MyCtrl($scope) {
  $scope.orders = [{
    status: 'my order1',
    outdated: '1'
  }, {
    status: 'my order2',
    outdated: '0'
  }];
}
<div ng-controller="MyCtrl">
  {{orders | myfilter}}
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.