Angular JS 'Startswith' custom filter

前端 未结 3 1134
滥情空心
滥情空心 2020-12-10 12:49

So I\'ve been trying a while to make a custom filter that searches for the \'Startswith\' parameters rather than the \'Contains\'. Every filter that I\'ve written haven\'t s

3条回答
  •  离开以前
    2020-12-10 13:27

    A simple way to do this is to add a new method to your scope.

    $scope.startsWith = function (actual, expected) {
        var lowerStr = (actual + "").toLowerCase();
        return lowerStr.indexOf(expected.toLowerCase()) === 0;
    }
    

    Then change the filter syntax on your element.

    Here is a working plunkr with the example above.

提交回复
热议问题