woutr_be
woutr_be

Reputation: 9722

Passing data to a template in ng-repeat

Consider the following structure:

<div id="jobs" ng-controller="JobsCtrl">
    <div class="job" ng-controller="JobCtrl" job-tpl ng-repeat="job in jobs"></div>
</div>

My JobsCtrl will handle date to create a list of items and some interaction for the entire item list, while JobCtrl will only handle interaction for single items.

Now how can I pass the data from JobsCtrl down to my JobCtrl?

At the moment JobsCtrl is just pretty basic and all it does is create some data and specify the template:

app.controller('JobsCtrl', function($scope) {
    $scope.jobs = [
    {
        'html': 'testing',
        'date': '23 saf',
        'type': 'job--hiring'
    },
    {
        'html': 'test',
        'date': '23 saf',
        'type': 'job--hiring'
    },
    {
        'html': 'test',
        'date': '23 saf',
        'type': 'job--hiring'
    },
    {
        'html': 'test',
        'date': '23 saf',
        'type': 'job--hiring'
    },
    {
        'html': 'test',
        'date': '23 saf',
        'type': 'job--hiring'
    }
]
}).directive('jobTpl', function() {
    return {
        restrict: 'A',
        templateUrl: 'job.html'
    }
})

But in my JobCtrl I want to modify that data and do some more stuff with it

app.controller('JobCtrl', function($scope) {
    // Handle data for one item here
})

How can I do something like this? Or am I just thinking in a wrong way?

Upvotes: 0

Views: 1144

Answers (1)

Alon Gubkin
Alon Gubkin

Reputation: 57119

Inside JobCtrl, $scope.job should work

Upvotes: 1

Related Questions