2016-08-21 12 views
0
<!DOCTYPE html> 
<html lang="en" ng-app="confusionApp"> 

<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head 
     content must come *after* these tags --> 
    <title>Ristorante Con Fusion: Menu</title> 
     <!-- Bootstrap --> 
    <link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> 
    <link href="../bower_components/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet"> 
    <link href="../bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet"> 
    <link href="styles/bootstrap-social.css" rel="stylesheet"> 
    <link href="styles/mystyles.css" rel="stylesheet"> 

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

    <div class="container"> 
      <div class="row row-content" ng-controller="dishDetailController as dishCtrl"> 
       <ul class="media-list"> 
        <li class="media" ng-repeat="dish in dishCtrl.dishes"> 
        <div class="media-left media-middle"> 
         <a href="#"> 
         <img class="media-object img-thumbnail" 
         ng-src={{dish.image}} alt="Uthappizza"> 
         </a> 
        </div> 
        <div class="media-body"> 
         <h2 class="media-heading">{{dish.name}} 
         <span class="label label-danger">{{dish.label}}</span> 
         <span class="badge">{{dish.price | currency}}</span></h2> 
         <p>{{dish.description}}</p> 
        </div> 
        <div ng-repeat="dish in dishCtrl.dishes" class="col-sm-8 col-sm-push-1"> 
         <form class="form-inline"> 
         <div class="form-group"> 
          <label class="form-control-static" style="font-size:20px;">Customer Comments</label> 
         </div> 
         <div class="form-group"> 
          <label>Sort by:</label> 
          <input type="text" class="form-control" ng-model="sort"> 
         </div> 
         </form> 
         <blockquote ng-repeat="c in dish.comments | orderBy:sort"> 
         <p>{{c.rating}}</p> 
         <p>{{c.comment}}</p> 
         <footer>{{c.author}} <cite title="Source Title">{{c.date | date : format : timezone}}</cite></footer> 
        </blockquote> 
         <form class="form-horizontal" name="userForm" ng-submit="submitForm(userForm.$valid)" noValidate> 
          <div class="form-group" ng-class="{ 'has-error' : userForm.name.$invalid && !userForm.name.$pristine }"> 
          <label class="col-sm-2 control-label">Your Name</label> 
          <div class="col-sm-10"> 
           <input type="text" name="name" class="form-control" placeholder="Enter your name" ng-model="user.name" required> 
           <p ng-show="userForm.name.$invalid && !userForm.name.$pristine" class="help-block">You name is required.</p> 
          </div> 
          </div> 
          <div class="form-group"> 
          <label class="col-sm-2 radio">Number of stars</label> 
          <div class="col-sm-10"> 
           <label class="radio-inline"> 
           <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1" ng-model="stars"> 1 
          </label> 
          <label class="radio-inline"> 
           <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2" ng-model="stars"> 2 
          </label> 
          <label class="radio-inline"> 
           <input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" ng-model="stars"> 3 
          </label> 
           <label class="radio-inline"> 
           <input type="radio" name="inlineRadioOptions" id="inlineRadio4" value="option4" ng-model="stars"> 4 
          </label> 
           <label class="radio-inline"> 
           <input type="radio" name="inlineRadioOptions" id="inlineRadio4" value="option5" ng-model="stars"> 5 
          </label> 
          </div> 
          </div> 
          <div class="form-group" ng-class="{ 'has-error' : userForm.comment.$invalid && !userForm.comment.$pristine }"> 
          <label class="col-sm-2 control-label">Your Comments</label> 
          <div class="col-sm-10"> 
           <textarea class="form-control" rows="3" name="comment" ng-model="user.comment" required></textarea> 
           <p ng-show="userForm.comment.$invalid && !userForm.comment.$pristine" class="help-block">You name is required.</p> 
          </div> 
          </div> 
          <div class="form-group"> 
          <div class="col-sm-offset-2 col-sm-10"> 
           <button type="submit" class="btn btn-primary">Submit Comment</button> 
          </div> 
          </div> 
         </form> 
        </div>       
       </li> 
      </ul> 
      </div> 
     </div> 
    <script src="../bower_components/angular/angular.min.js"></script> 
     <script> 
    (function(){ 
     var app = angular.module('confusionApp',[]); 
      app.controller('dishDetailController',['$scope', function($scope) { 

         var dishes=[ 
         { 
          name:'Uthapizza', 
          image: 'images/uthapizza.png', 
          category: 'mains', 
          label:'Hot', 
          price:'4.99', 
          description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.', 
          comments: [{ 
            rating:5, 
            comment:"Imagine all the eatables, living in conFusion!", 
            author:"John Lemon", 
            date:"2012-10-16T17:57:28.556094Z" 
           }, 
           { 
            rating:4, 
            comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", 
            author:"Paul McVites", 
            date:"2014-09-05T17:57:28.556094Z" 
           }, 
           { 
            rating:3, 
            comment:"Eat it, just eat it!", 
            author:"Michael Jaikishan", 
            date:"2015-02-13T17:57:28.556094Z" 
           }, 
           { 
            rating:4, 
            comment:"Ultimate, Reaching for the stars!", 
            author:"Ringo Starry", 
            date:"2013-12-02T17:57:28.556094Z" 
           }, 
           { 
            rating:2, 
            comment:"It's your birthday, we're gonna party!", 
            author:"25 Cent", 
            date:"2011-12-02T17:57:28.556094Z" 
           } 

           ] 

          } 
         ] 
         $scope.dishes = dishes; 
         $scope.stars= option5; 
          $scope.submitForm = function(isValid){ 
          if(isValid){ 

          } 
         }; 
        }]); 


     })(); 
    </script>`` 

</body> 
</html> 

私のアプリケーションはloading.If私は、コントローラがロードされているが、NG-repeatがないことを見ることができていないloading.Onデバッグ取り除いていますされますアプリケーションがロードしているスコープオブジェクト 誰かが私に解決策を教えてもらえますか?アプリケーションをロードしませんもされていない任意のエラーメッセージがコンソールに表示なっている

答えて

0

controller asの構文を使用していて、依然としてスコープ経由でデータにアクセスしようとしています。あなたのケースでは、controller as構文を使用すると、コントローラを 'エイリアス' DishCtrlでインスタンス化します。

コントローラでは、dishesをスコープのプロパティにする代わりに、コントローラーインスタンスでプロパティを作成します。線に沿って

何か:

var vm = this

vm.dishes = dishes

+0

私は確認する必要がありdishes.What変更にアクセスするには$スコープを使用する必要がありますか? – user3493243

+0

あなたのng-repeatは 'DishCtrl.dishes'ではなく' dish in dish'でなければなりません – Ladmerc

関連する問題