我正在尝试将我的范围用于编译....我希望每次单击一个按钮时,都会创建一个包含圆数的div。
main.controller('fightController', function($scope, $http, Services, $compile) {
$scope.doAFight = function(playerHab, monsterHab) {
Services.getFight(playerHab, monsterHab)
.success(function(data){
$scope.fight = data;
$scope.round = 0;
});
};
$scope.addRound = function() {
angular.element(document.getElementById('boiteCombat')).append($compile("
<div class=rondeCombat>
<div class=numRonde> Ronde " + $scope.round + " </div>
</div>
")($scope));
};
});
它只是给我一个错误,我正在尝试做的是非法......
答案 0 :(得分:3)
您希望操纵数据并让视图绑定生效,而不是自己操纵视图。使用ngRepeat
并添加到数组以获取更多行:
$scope.rounds = []; //lets this be the array we iterate over
$scope.addRound = function() {
$scope.rounds.push({round: $scope.round});
});
HTML:
<div id="boiteCombat">
<div class="rondeCombat" ng-repeat="round in rounds">
<div class=numRonde> Ronde {{round.round}} </div>
</div>
</div>