angularjs - Angular indexOf not outputting text -


i'm trying output name "sam" on screen in ng-show using indexof, nothing ever appears. appreciated.

html

   <head></head>    <body>       <div ng-controller="arraycontroller">          <div ng-repeat="product in products">             <div ng-show="product.name.indexof('sam') == 2">             </div>          </div>       </div>         <script src="bower_components/angular/angular.js"></script>       <script src="app.js"></script>    </body> </html> 

angular

var app = angular.module('myapp', []); app.controller('arraycontroller', ['$scope', function($scope){ $scope.products = [ { name: 'joe'  }, { name: 'bill' }, { name: 'sam' } ];  }]); 

possible solution using ng-if instead of ng-show

<body ng-app="myapp">       <div ng-controller="arraycontroller">         <div ng-repeat="product in products">           <div ng-if="product.name.indexof('sam') > -1">{{product.name}}           </div>         </div>       </div> </body>  var app = angular.module('myapp', []); app.controller('arraycontroller', ['$scope', function($scope){   $scope.products = [     {         name: 'joe'     },     {         name: 'bill'     },     {         name: 'sam'     }   ]; }]); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -