AngularJS:如何触发ng-repeat?

时间:2015-04-06 20:21:22

标签: angularjs angularjs-ng-repeat ng-repeat

我的控制器在生产中失败。一旦我纠正了问题,我手动实例化控制器,但不处理ng-repeat:

<html ng-app="MyApp">

<head>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="angular.js"></script>

  <script type="text/javascript">
  var isBreak = true;
  var Acme={};
  var app = angular.module('MyApp', [])
  .controller("Foo", function($scope, $timeout) {
    if(isBreak) {
      isBreak = false;
      throw "stuff";
    }
    $timeout(function() {
      $scope.stuff = ["one", "two"];
    })
  })
  .run(function($rootScope, $compile, $timeout) {
    Acme.$rootScope = $rootScope;
    Acme.$compile = $compile;
  });
  </script>
</head>
<body>
  <div id="parent">
    <div ng-controller="Foo">

      <p ng-repeat="s in stuff">{{s}}</p>
    </div>
  </div>
</body>
</html>

然后我输入控制台:

Acme.$compile($("#parent").contents())(Acme.$rootScope)

同一问题的其他帖子已经接受了答案,但他们没有解决问题。 (我在上面显示&#34;假&#34;例外。在实际代码中,异常是由其他原因引起的。)

0 个答案:

没有答案