filter 前方一致
// 前方一致コントローラー
app.controller("BeginWithMatch", function ($scope) {
$scope.filterCustom = function(expected, actual) {
// 入力した文字列の長さを取得
var len = actual.length;
// 前方一致
if(expected.substr(0, len) === actual) {
return expected;
}
};
$scope.items = [
{name:"AAA"},
{name:"BBB"},
{name:"ABC"},
{name:"AXC"}
];
});
filter 後方一致
// 後方一致コントローラー
app.controller("EndWithMatch", function ($scope) {
$scope.filterCustom = function(expected, actual) {
// 入力した文字列の長さを取得
var len = actual.length;
// 後方一致
if(expected.slice(-len) === actual || actual === "") {
return expected;
}
};
$scope.items = [
{name:"AAA"},
{name:"BBB"},
{name:"ABC"},
{name:"AXC"}
];
});