2017-10-17 9 views
0

ここに角の刻み目があります。指令への工場投入は機能していません

私の工場(beerFactory)をディレクティブに挿入しようとしていますが、リンク機能内からアクセスできません。

私のコードでわかるように、私はリンク機能の中にいったんログオンするとbeerFactoryオブジェクトをコンソールにしようとしています。

私は別のコントローラの中から使っているので、工場は正常に動作しています。

ます。また、引数として渡すために持っているもの、私は間違って

app.directive('starRating', ['beerFactory', function(){ 
 
    return { 
 
       restrict: 'EA', 
 
       scope: { 
 
        'value': '=value', 
 
        'max': '=max', 
 
        'hover': '=hover', 
 
        'isReadonly': '=isReadonly' 
 
       }, 
 
       link: function(scope, element, attrs, ctrl) { 
 
        
 
       console.log(beerFactory); 
 

 
         function renderValue() { 
 
          scope.renderAry = []; 
 
          for (var i = 0; i < scope.max; i++) { 
 
           if (i < scope.value) { 
 
            scope.renderAry.push({ 
 
             'fa fa-star fa-2x': true 
 
            }); 
 
           } else { 
 
            scope.renderAry.push({ 
 
             'fa fa-star-o fa-2x': true 
 
            }); 
 
           } 
 
          } 
 
         } 
 
        
 
         scope.setValue = function (index) { 
 
          if (!scope.isReadonly && scope.isReadonly !== undefined) { 
 
           scope.value = index + 1; 
 
          } 
 
         }; 
 
        
 
         scope.changeValue = function (index) { 
 
          if (scope.hover) { 
 
           scope.setValue(index); 
 
          } else { 
 
           // !scope.changeOnhover && scope.changeOnhover != undefined 
 
          } 
 
         }; 
 
        
 
         scope.$watch('value', function (newValue, oldValue) { 
 
          if (newValue) { 
 
           scope.updateRating(newValue); 
 
           renderValue(); 
 
          } 
 
         }); 
 
         scope.$watch('max', function (newValue, oldValue) { 
 
          if (newValue) { 
 
           renderValue(); 
 
          } 
 
         }); 
 
        
 
        }, 
 
       template: '<span ng-class="{isReadonly: isReadonly}">' + 
 
        '<i ng-class="renderObj" ' + 
 
        'ng-repeat="renderObj in renderAry" ' + 
 
        'ng-click="setValue($index)" ' + 
 
        'ng-mouseenter="changeValue($index, changeOnHover)" >' + 
 
        '</i>' + 
 
        '</span>', 
 
       replace: true 
 
      }; 
 
}]);

答えて

0

をやっていないという考えに:

app.directive('starRating', ['beerFactory', function(beerFactory){ 

https://docs.angularjs.org/guide/diを参照してください - >インライン配列アノテーション

このタイプのアノテーションを使用する場合は、アノテーション配列を関数宣言のパラメータと同期させてください。

+0

ありがとうございました。 –

関連する問題