加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularJS $compile没有定义

发布时间:2020-12-17 09:27:45 所属栏目:安全 来源:网络整理
导读:我正在尝试学习AngularJS,我正在尝试动态地编译一些DOM元素… 我试过演示: try { var templateHTML = angular.element('p{{total}}/p'),scope = ....; var clonedElement = $compile(templateHTML)(scope,function(clonedElement,scope) { //attach the clo
我正在尝试学习AngularJS,我正在尝试动态地编译一些DOM元素…
我试过演示:
try {
        var templateHTML = angular.element('<p>{{total}}</p>'),scope = ....;

        var clonedElement = $compile(templateHTML)(scope,function(clonedElement,scope) {
          //attach the clone to DOM document at the right place
        });

        //now we have reference to the cloned DOM via `clone`
} catch (ex) {
alert(ex.message);
}

但是我收回的是一个“$compile is not defined”

帮帮我!

在指令中使用$compile的示例代码.基本上继续首先将元素追加到DOM(可能希望保持不可见),然后通过使用finder来运行编译器,如rtcherry所提到的,应该注入$compile.
//
        componentModule.directive('getCompilerWk',function($compile) {
          return {
            restrict: 'A',link: function(scope,elm,attr) {
              elm.click(function(){
                    $(body).append(templateHTML);
                    $compile($(body).find('p'))(scope);

              })
            }
          };
        });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读