2017-11-13 3 views
0

私はこのカスタムディレクティブを持っています。 ng-repeatの中に、私の指示を以下のように呼んでいます。 'アイテム' としてng-repeat内のカスタムディレクティブ

selectedMealCalc.calculated_foods、オブジェクトの配列

<!-- DIRECTIVE --> 
    <div ng-repeat="option in [0,1,2,3,4]"> 
     <meal-option option="{{option}}" 
        items="selectedMealCalc.calculated_foods" 
        selectedmealcalc="selectedMealCalc"></meal-option> </div> 
    <!-- DIRECTIVE --> 

は、その後、私はangularjsでこのディレクティブを作成しています。

'use strict'; 

    angular.module('nutriApp').directive('mealOption', ['$compile', function($compile) { 
     return { 
     restrict: 'E', 
     templateUrl: 'views/checkins/meal-options.html', 
     scope: { 
      option: "@", 
      items: "=", 
      selectedmealcalc: "=" 
     }, 
     controller: ['$scope', 'Food', function($scope, Food) { 
      $scope.sumFood = {}; 
      $scope.summerizeOption = function(foods) { 
      if(foods.length > 0){ 
       $scope.sumFood = Food.summerize(foods); 
      } 
      return $scope.sumFood; 
      }; 
     }] 
     }; 
    }]); 

このHTMLディレクティブ。

<div class="row" ng-init="filteredItems = (items | filter: { food_option: option })" ng-controller="CheckinsPlansCtrl"> 
    <div class="col-md-12" ng-show="filteredItems.length > 0"> 
    Opção {{ option }} 
    <table class="table table-calculo table-striped"> 
     <thead> 
     <tr> 
      <th>Alimento</th> 
      <th>Quantidade</th> 
      <th></th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr ng-repeat="foodCalculation in filteredItems track by $index"> 
      <td>{{foodCalculation.food.name}}</td> 
      <td>{{foodCalculation.gram_amount}} g</td> 
     </tr> 
     </tbody> 
    </table> 
    </div> 
</div> 

selectedMealCalc.calculated_foodsを更新すると、カスタムディレクティブは更新されません。 改行を見て私のページでもう一度モーダルを閉じて開いてください。

+1

yea。あなたの問題はng-init https://stackoverflow.com/questions/25574048/does-ng-init-watch-over-change-on-instantiated-property-like-ng-model-does を使ってみてくださいあなたのコントローラにng-initロジックを見たり移動したりしてください。 –

+0

こんにちは@CharlieNgあなたの答えは正しいです。私の問題を解決しました。私はng-initのこの動作を知っていました。ありがとうございました。 –

+0

nice !!!!!!!!!!!! –

答えて

関連する問題