【问题标题】:$compile error in bundled angularJS?捆绑的 angularJS 中的 $compile 错误?
【发布时间】:2016-10-07 16:38:27
【问题描述】:

这是运行良好的未捆绑的角度代码。

angular.module('XXX').directive('xxx', ['$compile', '$injector', function($compile, $injector){
 return {
   restrict: 'A',
   scope: false,
   transclude: true,
  ...
  XXX.attachEvent("XXX", function(id){
   angular.element(document.querySelector( '[name="isallday"]' )).attr('ng-model', 'isallday');  
   angular.element( document.querySelector( ".dhx_section_time" )
            .getElementsByTagName("select") ).attr('ng-class', '{dhx_time_disable: isallday}').attr('ng-disabled', 'isallday');
   var el = angular.element(document.querySelector( ".dhx_cal_larea" ));    
   $injector = el.injector();
   $injector.invoke(function($compile){
      $compile(el)($scope)
   }) 
  })
}
}]);      

我动态添加了 ng-model,而不是静态添加。 但是当我在捆绑环境中运行这段代码时, 它显示一个错误。

未捕获的错误:[$injector:unpr] http://errors.angularjs.org/1.4.1/$injector/unpr?p0=tProvider%203C-%20t

我的项目使用 asp.net 和 angularjs 和 dhx。 我该如何解决这个错误?

【问题讨论】:

  • HTML 视图中包含哪些库?可以在这里分享一下吗?
  • 我正在使用 dhx 计划。所以我在显示 newEvent 对话框时添加了 ng-modal。
  • 尝试使用角度版本进行更改

标签: angularjs


【解决方案1】:

您的问题可能是以下几行中的缩小/丑化:

$injector.invoke(function($compile){
  $compile(el)($scope)
})

当被调用的函数被缩小/丑化时,它的第一个参数 $compile 在你的情况下被重命名为 t 导致未知的 tProvider 错误。请尝试以下操作:

$injector.invoke(['$compile', function($compile){
  $compile(el)($scope)
}])

(或重用您在指令中注入的$compile...)

【讨论】:

  • 非常感谢。我按照您的指南进行了修复。
猜你喜欢
  • 1970-01-01
  • 2018-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 2021-12-28
相关资源
最近更新 更多