Array indexOf
by nekyouto
HTML
<!-- stitch this with the module declare in Javascript -->
<body ng-app="myApp">
<div ng-controller="SelectCtrl">
<table>
<tr>
<td>The array contains 'apple': {{result1}}</td>
</tr>
<tr>
<td>The array contains 'pear': {{result2}}.</td>
</tr>
</table>
</div>
</body>
CSS
table {
width:100%;
}
tr {
width:100%;
}
td {
width:100%;
text-align:center;
}
JavaScript
// declare a module
var myApp = this.angular.module('myApp', []);
// declare a controller
myApp.controller('SelectCtrl', function ($scope) {
$scope.myData = ["apple", "banana", "pear", "pineapple"];
$scope.result1 = false;
$scope.result2 = false;
$scope.checkData = function () {
if ($scope.myData.indexOf("apple") != -1) {
$scope.result1 = true;
}
if (String($scope.myData).indexOf("pear") != -1) {
$scope.result2 = true;
}
}
$scope.checkData();
});