0

スコープの値にアクセスしようとしていますが、定義されていないと表示されています。 JSディレクティブでスコープが定義されていません

angular 
    .module("myApp",[]) 
    .controller('myCtrl', function($scope){ 
    var model=this; 
    }) 
    .directive ('ngCero', function($parse){ 
     var linkFunction =function(scope, element, attrs){ 
     element.bind("keypress", function(event) { 
     if(event.which === 44 || event.which === 13) { 
       console.log($parse(attrs.format)); 
      } 
     }); 
     }; 
     return{ 
     restrict : 'A', 
     } 
    }) 

答えて

0

マイHTML

<div ng-app="myApp" ng-controller="myCtrl as model"> 
    <input type="text" ng-model="model.cero" ng-cero="">  
    </div> 

私は

angular 
    .module("myApp",[]) 
    .controller('myCtrl', function($scope){ 
     var model=this; 
    }) 
    .directive ('ngCero', function($parse){ 
     var linkFunction =function(scope, element, attrs){ 
           element.bind("keypress", function(event) { 
           if(event.which === 44 || event.which === 13) { 
            console.log($parse(attrs.format)); 
           } 
           }); 
          }; 
     return{ 
      restrict : 'A', 
      scope:{ 
        cero:"ngModel" 
       }, 
      link: linkFunction 
     } 
}) 
を解決
関連する問題