Angular示例代码不起作用

时间:2017-10-04 10:43:12

标签: javascript html angularjs

我正在尝试创建示例角度应用程序,我已经初始化了一个角度应用程序并呈现了在控制器中定义的列表,但是我没有得到输出中的任何内容,甚至没有在javascript控制台中收到任何错误。

tsconfig.json

1 个答案:

答案 0 :(得分:3)

您应该 listctrl.list 而不是 var list = ['A','B','C','D'];

 listctrl.list = ['A','B','C','D'];

<强>样本

&#13;
&#13;
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>

<body ng-app="myApp">

<div ng-controller="ListController as listctrl">

  <ul>
    <li ng-repeat="i in listctrl.list">{{i}}</li>
  </ul>
</div>

<script type="text/javascript">
angular
  .module('myApp',[])
  .controller('ListController', function($scope) {
  
    var listctrl = this;
    listctrl.list = ['A','B','C','D'];
  })
</script>

</body>
</html>
&#13;
&#13;
&#13;