-1
如何檢查添加的單詞是否已存在,無論大小寫? 檢查是否區分大小寫,然後如果是,那麼它已經存在?Angular JS如何檢查添加的單詞是否已存在
app.controller("myCtrl", function($scope) {
$scope.products = ["BMW", "AUDI", "BENTLY"];
$scope.addItem = function() {
$scope.errortext = "";
if (!$scope.addMe) {return;}
if ($scope.products.lastIndexOf($scope.addMe) == -1)
{
$scope.products.push($scope.addMe);
}
else {
$scope.errortext = "The item is already in your shopping list.";
}
}
$scope.removeItem = function (x) {
$scope.errortext = "";
$scope.products.splice(x, 1);
}