我试图做的是,当单击图像时,我发送一个包含信息的数组放入函数'test',将它与来自另一个数据库的值进行比较,然后我试图返回正确的信息并显示它。代码:单击图像,然后显示来自数据库的信息
<div data-ng-repeat="hero in heroes | filter:search | orderBy:'id'">
<div class="wrap">
<img class="img-rounded" ng-src="images/heroes/{{hero.url}}_full.png" ng-click="test(hero.abilities)">
<div class="tooltip">
<p class="fat">{{hero.localizedName}}</p>
</div>
</div>
</div>
<div data-ng-repeat="ability in test| orderBy:'id'">
{{ability.localizedName}} //Should show the information of the selected hero
</div>
和脚本,
$scope.test = function(text){
var newSize = text.length;
var temp = [];
for(i = 0; i < newSize; i++)
{
for(j = 0; j < $scope.abilities.length; j++)
{
if($scope.abilities[j].id == text[i])
{
temp[i] = $scope.abilities[j];
}
}
}
//$scope.test = temp;
console.log(temp);
}
当我控制台记录了温度,我得到我想要的价值,但我不能获取值从机能恢复。
控制台只给我的错误消息说
“测试”未声明
,我已经搜索该错误消息,但我似乎并没有被能够找到我正在寻找的答案。
在此先感谢!
为$ scope.test在同一个控制器作为$ scope.heros? –
$ scope.heroes位于同一个控制器中,是的! –
你可以发布你的完整控制器吗? –