1. 程式人生 > >未解決的問題:ngRepeat如何在拼接字串模板中使用?

未解決的問題:ngRepeat如何在拼接字串模板中使用?

這是我寫的一個例子,但是報錯

<!DOCTYPE html>
<html ng-app="app">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>ngRepeat</title>
    <link rel="stylesheet" href="">
</head>
<body ng-controller="ctrlApp"
>
</body> <script src="../../lib/js/angular.js"></script> <script> var app = angular.module('app', []); app.controller('ctrlApp', ['$scope', '$compile', function($scope, $compile) { $scope.a = [1,2,3,4]; var html = ''; html += '<div ng-repeat="a in as">{{a}}</div>'
; var temp = $compile(html)($scope); document.body.innerHTML = temp; }]);
</script> </html>

這裡寫圖片描述 不知道怎麼解決?