【问题标题】:AngularJS $compile is not a functionAngularJS $compile 不是一个函数
【发布时间】:2017-04-25 07:11:44
【问题描述】:

我尝试使用 angular 将字符串变量转换为 html,我收到 $compile 组件建议但出了点问题

我的控制器:

ChatZamba.controller("ScriptController", ['$scope', '$compile', function ($scope, $timeout, $compile) {

还有我的角度函数:

function build_step_view(data, i){
    if(data != undefined){
        var tmp = $compile($('.detail-script-list'))(scope);
        $('.detail-script-list').append(tmp);
    }
}

但是当触发我的函数时,我在 Chrome 编译器中得到TypeError: $compile is not a function

帮帮我!谢谢!

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    控制器代码应该是这样的:

    ChatZamba.controller("ScriptController", ['$scope', '$timeout', '$compile', function ($scope, $timeout, $compile) {
    }
    

    您忘记注入 $timeout 服务的引用。

    【讨论】:

      猜你喜欢
      • 2014-08-08
      • 2015-09-12
      • 2016-05-21
      • 2018-06-27
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 2016-07-12
      相关资源
      最近更新 更多