如何将 return 函数绑定到标记 angular
How to bind return function to markup angular
<li ng-click="toggleTables('all')" class="active">
<span>All Tags (getTotal('allTerms'))
<span ng-bind="getTotal('allTerms')"></span>
</span>
</li>
我正在尝试从函数 getTotal
获取返回值以显示在标记中,但是该值未显示,函数如下:
function getTotal(key) {
console.log('getTotal',key);
return totals[key].totals; // 33
}
你在使用控制器吗?如果是这样,你为什么不使用像这样的变量呢
$scope.total = 0;
function getTotal(key) {
$scope.total = totals[key].totals;
}
<span ng-bind="total"></span>
你也可以绑定函数。检查样本 - https://jsfiddle.net/dkjk6bng/
<span ng-bind="getTotal('allTerms')"></span>
var app = angular.module('app', []);
app.controller("mainCtrl", function($scope) {
$scope.totals = {
'allTerms': {
totals: 33
}
};
$scope.getTotal = function(key) {
console.log('getTotal', key);
return $scope.totals[key].totals; // 33
}
});
希望对您有所帮助! :)
试试这个
<span>{{getTotal('allTerms')}}</span>
<li ng-click="toggleTables('all')" class="active">
<span>All Tags (getTotal('allTerms'))
<span ng-bind="getTotal('allTerms')"></span>
</span>
</li>
我正在尝试从函数 getTotal
获取返回值以显示在标记中,但是该值未显示,函数如下:
function getTotal(key) {
console.log('getTotal',key);
return totals[key].totals; // 33
}
你在使用控制器吗?如果是这样,你为什么不使用像这样的变量呢
$scope.total = 0;
function getTotal(key) {
$scope.total = totals[key].totals;
}
<span ng-bind="total"></span>
你也可以绑定函数。检查样本 - https://jsfiddle.net/dkjk6bng/
<span ng-bind="getTotal('allTerms')"></span>
var app = angular.module('app', []);
app.controller("mainCtrl", function($scope) {
$scope.totals = {
'allTerms': {
totals: 33
}
};
$scope.getTotal = function(key) {
console.log('getTotal', key);
return $scope.totals[key].totals; // 33
}
});
希望对您有所帮助! :)
试试这个
<span>{{getTotal('allTerms')}}</span>