Search code examples
angularjsangularjs-ng-repeatangular-strap

How to pass local scope of nested ng-repeat element with ng-blur?


I have three nested ng-repeatelements. I would like to access the scope of the elements in the innermost nested ng-repeat with a function called by ng-blur.

I know I can access the scope of the innermost nested element with a listener on the AngularStrap typeahead. It's the $scope property of the fourth parameter, elem, in the listener shown in this forum: https://github.com/mgcrea/angular-strap/issues/81.

How can I pass this elem object to my controller with ng-blur?


Solution

  • So in the case of the following ng-repeats:

    <div ng-repeat="continent in continents">
        <div ng-repeat="country in continent.countries">
            <div ng-repeat="city in country.cities">
                <input type="text" ng-blur="myFunction()">
            </div>
        </div>
    </div>
    

    You can access the scope of the most nested city <div> in your controller like so:

    $scope.myFunction = function(){
        console.log(this.city);
        console.log(this.city.someVariable);
    }