How to generates dynamically ng-model=”my_{{$index}}” with ng-repeat in AngularJS?

Does it solve your problem? function MainCtrl($scope) { $scope.queryList = [ { name: ‘Check Users’, fields: [ “Name”, “Id”] }, { name: ‘Audit Report’, fields: [] }, { name: ‘Bounce Back Report’, fields: [ “Date”] } ]; $scope.models = {}; $scope.$watch(‘selectedQuery’, function (newVal, oldVal) { if ($scope.selectedQuery) { $scope.parameters = $scope.selectedQuery.fields; } }); } And … Read more

Highlighting a filtered result in AngularJS

In did that for AngularJS v1.2+ HTML: <span ng-bind-html=”highlight(textToSearchThrough, searchText)”></span> JS: $scope.highlight = function(text, search) { if (!search) { return $sce.trustAsHtml(text); } return $sce.trustAsHtml(text.replace(new RegExp(search, ‘gi’), ‘<span class=”highlightedText”>$&</span>’)); }; CSS: .highlightedText { background: yellow; }

Binding inputs to an array of primitives using ngRepeat => uneditable inputs

Can anyone explain to me why are the inputs uneditable/readonly? If it’s by design, what’s the rationale behind? It is by design, as of Angular 1.0.3. Artem has a very good explanation of how 1.0.3+ works when you “bind to each ng-repeat item directly” – i.e., <div ng-repeat=”num in myNumbers”> <input type=”text” ng-model=”num”> When your … Read more

Angular passing scope to ng-include

Late to the party, but there is a little angular ‘hack’ to achieve this without implementing a dumb directive. Adding a built-in directive that will extend your controller’s scope (like ng-if) everywhere you use the ng-include will actually let you isolate the variable name for all the included scopes. So: <div ng-include=”‘item.html'” ng-if=”true” onload=”item = … Read more

How to obtain previous item in ng-repeat?

You can do something like <div ng-app=”test-app” ng-controller=”MyController”> <ul id=”contents”> <li ng-repeat=”content in contents”> <div class=”title”>{{$index}} – {{content.title}} – {{contents[$index – 1]}}</div> </li> </ul> </div> JS var app = angular.module(‘test-app’, []); app.controller(‘MyController’, function($scope){ $scope.contents=[{ title: ‘First’ }, { title: ‘Second’ }, { title: ‘Third’ }] }) Demo: Fiddle Be careful: $index is for the directive … Read more