将数据传递到ng-repeat中的模板

时间:2014-01-14 07:37:22

标签: angularjs

考虑以下结构:

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

我的JobsCtrl将处理日期以创建项目列表以及整个项目列表的一些互动,而JobCtrl仅处理单个项目的互动。

现在我如何将数据从JobsCtrl传递到我的JobCtrl

目前JobsCtrl非常基本,它所做的就是创建一些数据并指定模板:

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'
    }
})

但在我的JobCtrl中,我想修改这些数据,并用它做更多的事情

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

我该怎么办?或者我只是以错误的方式思考?

1 个答案:

答案 0 :(得分:1)

JobCtrl内,$scope.job应该有效