$ scope.myFunc()不是函数 [英] $scope.myFunc() is not a function
本文介绍了$ scope.myFunc()不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将$ scope.span00,span01,span10等绑定到网格中.
I'm trying to ng-bind $scope.span00, span01, span10, and so on in a grid.
$scope.span01 = 'test'; // this works fine
现在可以进行ng-点击...
Now for the ng-click...
$scope.clickedOn = function(row, column) {
var gridLocation = function() { return 'span'.concat(row).concat(column); } // returns span01
$scope.gridLocation() = 'test'; // says $scope.gridLocation() is not a function.
}
这不是函数.我在这里做什么?
It's saying it's not a function. What do I do here?
推荐答案
因为该函数在 $ scope
上不存在.这是您需要做的:
Because the function does not exist on $scope
. This is what you need to do:
$scope.gridLocation = function (row, column) {
return 'span'.concat(row).concat(column);
};
$scope.clickedOn = function (row, column) {
$scope.gridLocation(row, column);
};
修改
按照评论中的要求进行操作(希望我理解正确):
To do what you asked for in the comments (I hope I understood correctly):
$scope.clickedOn = function (row, column) {
$scope[$scope.gridLocation(row, column)] = 'test';
};
这篇关于$ scope.myFunc()不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文