我试图从模板的函数中获取id,但我无法得到它。没有参数我可以很容易地调用一个函数,但有参数,我不知道如何做到这一点。到目前为止,这就是我所做的。
指令模板(求职Html)
<div class="artist-job-search-filters">
<div class="foo" ng-click="$ctrl.changeArtistJobFilter(1)" ng-class="$ctrl.searchFilterAll ? 'artist-filter-selected' : 'artist-filter'">All</div>
<div class="foo" ng-click="$ctrl.changeArtistJobFilter(2)" ng-class="$ctrl.searchFilterJob ? 'artist-filter-selected' : 'artist-filter'">Job</div>
<div class="foo" ng-click="$ctrl.changeArtistJobFilter(3)" ng-class="$ctrl.searchFilterStandBy ? 'artist-filter-selected' : 'artist-filter'">Standby</div>
<div class="foo" ng-click="$ctrl.changeArtistJobFilter(4)" ng-class="$ctrl.searchFilterAudition ? 'artist-filter-selected' : 'artist-filter'">Audition</div>
<div class="foo" ng-click="$ctrl.changeArtistJobFilter(5)" ng-class="$ctrl.searchFilterApplied ? 'artist-filter-selected' : 'artist-filter'">Applied</div>
</div>
这里changeArtistJobFilter
是我的功能,我正在传递价值观。以下是我的directive.js
Directive.js
app.directive('jobsSearch', function () {
return {
restrict: 'EA',
scope: {
'artistSearchModel': "=",
'showDropdown': "=",
'operaticRoleSearchResult' : "=",
'viewAllJobs' : "&",
'musicalWorkSearchResult' : "=",
'institutionSearchResult' : "=",
'changeArtistJobFilter' : "&",
'searchFilterAll' : "=",
'searchFilterJob' : "=",
'searchFilterStandBy' : "=",
'searchFilterAudition' : "=",
'searchFilterApplied' : "=",
'searchArtistJob': "&"
},
controller: function () { },
controllerAs: '$ctrl',
bindToController: true,
templateUrl: '/views/profile/directives/job_search.html'
};
});
以下是我称之为指令的观点。
使用指令
查看Html<jobs-search artist-search-model="jobDashboard.artistSearchModel"
search-artist-job="jobDashboard.searchArtistJob()"
show-dropdown="jobDashboard.showDropdown"
operatic-roleSearch-result="jobDashboard.operaticRoleSearchResult"
view-all-jobs="jobDashboard.viewAllJobs()"
musical-work-search-result="jobDashboard.musicalWorkSearchResult"
institution-search-result="jobDashboard.institutionSearchResult"
change-artist-job-filter="jobDashboard.changeArtistJobFilter()"
search-filter-all="jobDashboard.searchFilterAll"
search-filter-job="jobDashboard.searchFilterJob"
search-filter-stand-by="jobDashboard.searchFilterStandBy"
search-filter-audition="jobDashboard.searchFilterAudition"
search-filter-applied="jobDashboard.searchFilterApplied"
></jobs-search>
答案 0 :(得分:0)
只需在函数内部调用指令
change-artist-job-filter="jobDashboard.changeArtistJobFilter(**filter**)"