我有一个方法:
<span ng-init="getJobApplicantsList(jobId)">(number should be display here)</span>
是否可以显示数据而不将其存储到范围变量
中因为我在很多地方使用这种方法。
这是我的控制者:
var set = [blah,blah];//object
$scope.getJobApplicantsList = function(jobId) {
findByMatchingProperties(set, { jobId: jobId }).length; //i have a function and i'm getting number here Example:`250` int
}
我想要这样的事情:
<span>{{getJobApplicantsList(jobId)}}</span>
答案 0 :(得分:2)
只需返回号码
$scope.getJobApplicantsList = function(jobId) {
return findByMatchingProperties(set, { jobId: jobId }).length;
}
并在模板中调用该函数
<span>{{getJobApplicantsList(jobId)}}</span>
答案 1 :(得分:1)
只需从函数返回值,无需将其存储到任何范围变量中。
您还可以使用 -
来避免使用$ scopeJS -
var vm = this;
vm.getJobApplicantsList = function (jobId) {
return findByMatchingProperties(set, { jobId: jobId }).length;
}
HTML -
<div ng=controller="AppController as vm">
<span ng-bind="vm.getJobApplicantsList(jobId)"></span>
</div>