我的AngularJS代码不起作用

时间:2015-09-25 16:04:13

标签: javascript angularjs angularjs-scope angularjs-ng-repeat

我正在学习AngularJS并最终获得了ToDoList基本应用程序的以下代码。我在浏览器中看到它不起作用。我是Angular的新手并且可能没有明显的东西,所以我想如果我的应用名称是

todoApp

然后我应该把

$scope.todoApp

而不是

$scope.todo

但结果证明这不是问题。

  <!DOCTYPE html>
  <html ng-app="todoApp">
  <head>
    <title>To DO List</title>
    <link href="bootstrap.css" rel="stylesheet">
    <link href="bootstrap-theme.css" rel="stylesheet>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript">
         var model = {
             user: "Adam",
             items: [{ action: "Buy flowers", done: false },
                    { action: "Get Shoes", done: false },
                    { action: "Collect Tickets", done: true },
                    { action: "Call Joe", done: false }]
            };
         var todoApp = angular.module("todoApp", []);

         todoApp.controller("ToDoCtrl", function($scope) {
            $scope.todo = model;
          });
    </script>
  </head>
 <body ng-controller="ToDoCtrl">
   <div class="page-header">
     <h1>
        {{todo.user}}'s To Do List
        <span class="label label-default">{{todo.items.length}}</span>
     </h1>
   </div>
  <div class="panel">
    <div class="input-group">
        <input class="form-control" />
        <span class="input-group-btn">
            <button class="btn btn-default">Add</button>
        </span>
    </div>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Description</th>
                <th>Done</th>
            </tr>
        </thead>
        <tbody>
             <tr ng-repeat="item in todo.items">
                <td>{{item.action}}</td>
                <td><input type="checkbox" ng-model="item.done" /></td>
                <td>{{item.done}}</td>
             </tr>
          </tbody>
        </table>
     </div>
   </body>
</html>

这就是我在浏览器中获得的内容.. enter image description here

这就是我想我应该得到的...... enter image description here

为什么它不起作用?

1 个答案:

答案 0 :(得分:2)

由于您在链接标记的HTML属性中缺少",因此rel无效。你错过了这里:

<link href="bootstrap-theme.css" rel="stylesheet>
                                                ^ ==> missing "

Working DEMO /* updated css */

查看DEMO中的无效HTML。在link标记后,您可以看到HTML为绿色。