0

In AngularJS, I have a ng-repeat for . Now what I want to do -

On ng-repeat, I want to do ng-init like

<tr ng-repeat="blah in blah" ng-init($event) />

The $event works fine with ng-click($event). How to do the same for ng-init?

anand patil
  • 507
  • 1
  • 9
  • 26

2 Answers2

1

In HTML

<tr ng-repeat="blah in blahs"  ng-init="$last && done()" />

Inside your controller

function myControllerFunc($scope, $element){
    $scope.done= function(){
       //do something with $element
    }
}
Cyril Cherian
  • 32,177
  • 7
  • 46
  • 55
0

In ng-init cannot exists $event. Use a directive.

<div ng-app="myApp" ng-controller="myCtrl">
   <input type="text" my-ng-init="myFunc"><br>
</div>

<script>
var app = angular.module('myApp', []);
app.directive('myNgInit', function() {
  return {
    scope: {
     myNgInit: '&'
    },
    link: function(scope, element, attributes) {
    scope.myNgInit()(element);
    }
  };
});

app.controller('myCtrl', function($scope) {
   $scope.myFunc= function($element) {
    console.log($element);
   }
});
</script>
Laurianti
  • 903
  • 1
  • 5
  • 19