2

一个跟进这个问题:AngularJS data bind in ng-bind-html?

,如果有什么,我想插连接到NG-重复创建范围值是多少?

myDict = {'Suggestion' : $interpolate('Vote here if you think {{player.name}} is right!')($scope) 
      ...};// $scope is wrongly passed here as 'player' is not a scope variable, 

然后

<div ng-repeat="player in players"> <span ng-bind-html="myDict['Suggestion']"></span> </div>

是否有可能做这样的事情没有自定义指令?

回答

1

值得庆幸的是,你当你调用该函数的一个决定:

$scope.myDict = function (scope) { 
    return {'Suggestion' : $interpolate('Vote here if you think {{player.name}} is right!')(scope); 
} 

然后在你的HTML:

<div ng-repeat="player in players"> 
    <span ng-bind-html="myDict({player: player})['Suggestion']"></span> 
</div> 

这将再次调用该函数每位玩家一个对象文本,并将其作为$interpolate调用的“范围”。


但是,请注意:如果您有数千条记录,则每次调用函数都可能会有某种性能。击中。我能想到的唯一方法是在$interpolate调用中使用{{players[$index].name}} ...