-2

Is it possible to declare ng-repeat elements inside of javascript. I googled try to find the answer but I could not find. If other ways is there please give some ideas I am really lost my way right now.
Thank you

HTML

<div class="" ng-app='app' ng-controller='appCtrl'>
    <div ng-repeat='el in names'>
        <div ng-click="click">{{el}}</div>
    </div>
</div>

JavaScript

var app = angular.module('app', [])
var appCtrl = function ($scope) {
    $scope.names = [{
        name: 'jane'
    }, {
        name1: 'jane1',
        name2: 'jane2'
    }, {
        name3: 'jane3'
    }];
    $scope.click = {
        // I want to declare this part 
        //
        //
        // if (el.length() == 2) {
        //     alert('true')
        // }
    }
}

app.controller('appCtrl', appCtrl())

FIDDLE

Shaxrillo
  • 769
  • 1
  • 7
  • 24

1 Answers1

0

Check this answer I used input tags for the demo purpose.

<div class="" ng-app='app' ng-controller='appCtrl'>
<div ng-repeat='el in names'>
    <input  id="{{el.id}}" ng-click="clickz(el.id)" value = "{{el}}" > {{el}}</input>
</div>
</div>

The function clickz. If the number of names are equal to 2 it will alert.

$scope.clickz = function(id){
    //alert(id); 
    var len = document.getElementById(id).value.split(",").length-1;

    if(len == 2 ){
        alert(true)
    }

}
prime
  • 14,464
  • 14
  • 99
  • 131