2016-12-03 4 views
0

次のコードでは、「details.html」ページで{{msg}}の返品のみを受け取ります。私はリテラルなどを得ることができます.....しかし、他に何もありません。私はそれが何か簡単だと確信していますが、私がしようとしているのは、ボタンをクリックすると "todo"のタイトルが私のリストの外に表示されるようにすることです。どんな助けでも大歓迎です。 [詳細]ボタンをクリックすると、実際のリストの下にタイトルが表示されます。ここで角度ルーティングで混乱しています

app.controller("detailsCtrl", function($scope) { 
    $scope.msg = (todo.title); 
}); 

TODOで

 <!DOCTYPE html> 
<html ng-app="homework"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>Untitled Document</title> 
    <!-- Bootstrap --> 
    <link href="css/bootstrap.css" rel="stylesheet"> 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.9/angular.min.js"></script> 
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script> 
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
    <!--[if lt IE 9]> 
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
     <![endif]--> 
    </head> 
    <body> 

    <html ng-app="homework"> 
    <body> 

        <form ng-controller="TodoController as todoCtrl" 
          ng-submit="addTodo()"> 
          <!-- add Bootstrap and AngularJS HTML Form here --> 
          <div class="form-group col-sm-6"> 
           <label for="todoTitle">Short Name</label> 
           <input id="todoTitle" class="form-control" type="text" 
            ng-model="todoTitle"> 
          </div> 
          <div class="form-group col-sm-6"> 
           <label for="todoDescription">Description</label> 
           <input id="todoDescription" class="form-control" type="text" 
            ng-model="todoDescription"> 
          </div> 
          <div class="form-group"> 
           <input class="btn btn-primary" type="submit" value="Add New"> 
          </div> 
          <!-- Display table if todoList has more than one object --> 
          <div ng-if="todoList.length > 0"> 
           <table class="table table-striped"> 
            <th>ToDo Name</th> 
            <th>Description</th> 
            <th>Date</th> 
            <th>Complete</th> 
            <!-- loop over arry of todos --> 
            <tr ng-repeat="todo in todoList track by $index"> 
             <td ng-bind="todo.title"></td> 
             <td ng-bind="todo.description"></td> 
             <td ng-bind="todo.date | date:'MMM d, yyyy'"></td> 
             <td ng-click="deleteTodo()"><span class="glyphicon glyphicon-remove" style="color: red;"></span></td> 
             <td><a href="#details">Details</a></td> 
             <td ng-click="testTodo()"><span class="glyphicon glyphicon-ok" style="color: blue;"></span></td> 
            </tr> 
           </table> 
          </div> 
        </form>  

     <div ng-view></div> 




    <script> 
    var app = angular.module('homework', ['ngRoute']); 
         app.controller('TodoController', function($scope) { 
          $scope.todoList = []; 

          $scope.addTodo = function() { 
           $scope.todoList.push({ 
            title:$scope.todoTitle, 
            description:$scope.todoDescription, 
            date:new Date() 
            }); 
           $scope.todoTitle = ""; 
           $scope.todoDescription = ""; 
          }; 

          $scope.deleteTodo = function(){ 
           $scope.todoList.splice(this.$index, 1); 
          }; 

          $scope.testTodo = function(){ 
           alert(this.todo.title); 
          } 
         }); 

     app.config(function($routeProvider){ 
      $routeProvider 
      .when("/", { 
       templateUrl: "blank.html" 
      }) 
      .when("/details", { 
       templateUrl: "details.html", 
       controller: "detailsCtrl" 
      }); 
    }) 
     app.controller("detailsCtrl", function($scope){ 
      $scope.msg = (todo.title); 
     }); 


     </script> 

     </body> 
</html> 






    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.11.3.min.js"></script> 

    <!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.js"></script> 
    </body> 
</html> 

"details.html" の問題がある

<!doctype html> 
<html> 
    <h1>{{msg}}</h1> 
</html> 
+0

Wazzupを変更することで、この作業を見ることができます? – Endless

答えて

0

は、したがって、TODOが不定となり、それは新しいインスタンスを作成し、定義されていません。 service/factoryを使用してコントローラ間でデータを渡す必要があります。 あなたが ``後のjQueryを含ん下のコードで

app.controller("detailsCtrl", function($scope) { 
    $scope.msg = "test"; 
}); 

DEMO

+0

私はすでに文字列を使って渡すことができました。それは私が求めていたものではありません。 –

関連する問題