嘿。我有一个ng重复表(星期天是一个表)
,我有一个带有工作程序ID并返回名为GetWorkerName的工作程序名称的函数 如何在不单击功能的情况下重复调用该功能?请帮助我:)
$scope.GetWorkerName=function(workerid){
$http.get("/ShiftWeb/rest/worker/getworkername?id="+workerid)
.then(function(response){
$scope.getWorkerName=response.data;
})
};
HTML:
-
<table class="table table-bordered table-striped">
<tr>
<th>Sunday</th>
</tr>
<tr ng-repeat="settingtime in settingtimes | orderBy:'time' |
filter:by_shiftDay" ng-if="settingtime.shiftDay=='SUNDAY'">
<td>
{{settingtime.time}}
</br>
<div style="border: 1px solid red" ng-repeat="sidor in nextsidor" ng-
if="sidor.shiftTime==settingtime.id">
Worker: {{sidor.worker}}
{{getWorkerName}}
</br>
Role : {{sidor.role}}
</br><button class="btn btn-primary" ui-sref="sidor" ng-
click="RemoveShift(sidor.id)">Remove Shift</button>
</div>
</br><button class="btn btn-primary" ui-sref="sidor" ng-
click="CreateShift(settingtime.id)">Create Shift</button>
</tr>
</table>
答案 0 :(得分:1)
您可能想要做的是创建一个指令,该指令可以获取ID并返回所需的任何数据。然后,您可以在其他地方重用它。
使用指令:
<worker id="231"></worker>
定义指令:
(function(){
angular.module('example').directive('worker', ['workerService', function(workerService){
function link($scope, element, attrs) {
$scope.workerName = workerService.getName(attrs.id);
};
return {
template: '(<span>{{ workerName }}</span>)',
link: link
};
}]);
})();