私は次のHTMLを持っています
<span class="items-count">{{items | countmessage}}</span>
そして、次のフィルターは正しいカウントメッセージを表示します
app.filters
.filter('countmessage', function () {
return function (input) {
var result = input.length + ' item';
if (input.length != 1) result += 's';
return message;
}
});
しかし、「item(s)」の代わりに別の単語を使用したいので、フィルターを変更しました
app.filters
.filter('countmessage', function () {
return function (input, itemType) {
var result = input.length + ' ' + itemType;
if (input.length != 1) result += 's';
return message;
}
});
そのような文字列を使用すると機能します
<span class="items-count">{{items | countmessage:'car'}}</span>
ただし、$ scopeの変数では機能しません。$scope変数を使用することは可能ですか?
<span class="items-count">{{items | countmessage:itemtype}}</span>
ありがとう