Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs如何解决指令中的未知提供程序错误_Angularjs_Angularjs Directive_Angularjs Provider - Fatal编程技术网

Angularjs如何解决指令中的未知提供程序错误

Angularjs如何解决指令中的未知提供程序错误,angularjs,angularjs-directive,angularjs-provider,Angularjs,Angularjs Directive,Angularjs Provider,我的meanjs应用程序中出现以下错误- Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- uiJqDirective http://errors.angularjs.org/1.4.7/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20uiJqDirective at REGEX_STRING_REGEXP (a

我的meanjs应用程序中出现以下错误-

Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- uiJqDirective
http://errors.angularjs.org/1.4.7/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20uiJqDirective
    at REGEX_STRING_REGEXP (angular.js:68)
    at angular.js:4289
    at Object.getService [as get] (angular.js:4437)
    at angular.js:4294
    at getService (angular.js:4437)
    at Object.invoke (angular.js:4469)
    at angular.js:7080
    at forEach (angular.js:336)
    at Object.<anonymous> (angular.js:7078)
    at Object.invoke (angular.js:4478)

错误:[$injector:unpr]未知提供程序:$scopeProvider不注入$scope。相反,替换compile by link,它的第一个参数是作用域:

link: uiJqLinkingFunction(scope, tElm, tAttrs) {

您不必在指令中注入scope,只需删除数组中的
$scope

directive('uiJq', [
  '$scope', // YOU HAVE TO REMOVE THIS!
  'uiJqConfig', 
  'JQ_CONFIG', 
  'uiLoad', 
  '$timeout', 
  function uiJqInjectingFunction(
    $scope, // REMOVE THIS AS WELL
    uiJqConfig, 
    JQ_CONFIG, 
    uiLoad, 
    $timeout) { 

     /* ... */ 

  }])
在编译函数返回的链接函数中已经有了指令的作用域

return function uiJqLinkingFunction($scope, elm, attrs) {
  /* ... */
};
因此,您的指令应仅注入以下内容:

directive('uiJq', [
  'uiJqConfig', 
  'JQ_CONFIG', 
  'uiLoad', 
  '$timeout', 
  function (
    uiJqConfig, 
    JQ_CONFIG, 
    uiLoad, 
    $timeout) { 

     /* ... */ 

  }])

您不需要注入$scope。在注入scope之前,我遇到了这个错误--'32angular.js:12477 TypeError:Cannot read属性'apply',undefined at ui jq.js:59 at angular.js:17855 at completeOutstandingRequest(angular.js:5507)at angular.js:5784'
directive('uiJq', [
  'uiJqConfig', 
  'JQ_CONFIG', 
  'uiLoad', 
  '$timeout', 
  function (
    uiJqConfig, 
    JQ_CONFIG, 
    uiLoad, 
    $timeout) { 

     /* ... */ 

  }])