小编And*_*han的帖子

如何在AngularJS中使用ng-repeat插入html代码?

我想使用ng-repeat在div中创建一行按钮.然后以某种方式克隆/复制该div.

基本上所以它看起来像这样;

[0] [0] [0] [0]

而且我也想制作下面重复的div.我之前使用过克隆,但我需要使用ng-repeat,但这并不成功.

<body ng-app="myApp" ng-controller="myCtrl">
...
...
...
<div id="boxHolder">
<span id="musicBox" ng-repeat="x in instrumentBtns">
{{x}}
</span>
</div>
Run Code Online (Sandbox Code Playgroud)

这就是我的html.到目前为止,我的app.js文件看起来像这样.

var app = angular.module("myApp", []);

app.controller("myCtrl", function($scope) {
  $scope.instrumentBtns = [
    '<button id="inst0">0</button>',
    '<button id="inst1">0</button>',
    '<button id="inst2">0</button>',
    '<button id="inst3">0</button>',
  ]
});
Run Code Online (Sandbox Code Playgroud)

首先发布到StackOverflow,所以如果我不清楚请告诉我!谢谢!

html javascript angularjs ng-repeat angularjs-ng-repeat

5
推荐指数
1
解决办法
1107
查看次数