簡體   English   中英

我的 AngularJS 代碼不起作用

[英]My AngularJS code doesn't work

我正在學習 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>

這就是我在瀏覽器中得到的.. 在此處輸入圖片說明

這就是我想我應該得到的...... 在此處輸入圖片說明

為什么它不起作用?

你的HTML變得無效,因為你在鏈接標簽的rel屬性中缺少" 。在這里你丟失了:

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

工作演示/* updated css */

看看DEMO中的 Invalid HTML 。 在這里你可以看到link標簽 HTML 被染成綠色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM