简体   繁体   中英

My AngularJS code doesn't work

I am learning AngularJS and ended up with the following code for ToDoList basic app. I viewed it in a browser it didn't work. I am new to the Angular and mightn't get obvious things, so I thought if my app name is

todoApp

Then I should put

$scope.todoApp

instead of

$scope.todo

but turned out that's not an issue.

  <!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>

That's what I get in a browser.. 在此处输入图片说明

And that's what I guess I am supposed to get... 在此处输入图片说明

Why it doesn't work?

Your HTML getting invalid because you are missing " in link tag's rel attribute. Here you are missing:

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

Working DEMO /* updated css */

Have a look at Invalid HTML in DEMO . Here you can see after link tag HTML is colored green.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM