将$ http注入指令控制器

sis*_*imh 2 angularjs angularjs-directive

我试图将$ http注入指令控制器,如下所示:

JS

app.direcitve('customDirecitve',function(){
     return : 'E',
     scope : {
         url : "@",
         urlParams : "@"
     } ,
     controller  : ['$scope', '$http', function($scope, $element, $attrs, $transclude,$http) { 
         $http.post($scope.url,$scope.urlParams).success(function (data) {  

         });
    ]};        
});
Run Code Online (Sandbox Code Playgroud)

这次注射有什么问题?

小智 10

您必须遵守注射的相同订单:

controller  : ['$scope','$element', '$attrs', '$transclude', '$http',  function($scope, $element, $attrs, $transclude, $http) { 
         $http.post($scope.url,$scope.urlParams).success(function (data) {  

         });
Run Code Online (Sandbox Code Playgroud)