繁体   English   中英

为什么angular不解析我的模板?

[英]Why is angular not parsing my template?

我有一个角度指令,在该指令加载后,我通过templateCache编译模板。 由于某种原因,我的{{}}会在模板中输出,而不是被解析并替换为其各自的值。 有人知道为什么吗?

模板看起来像这样

 <script type="text/ng-template" id="input">
        <input class="cirque-input" ng-model="model" value="{{model}}" type="{{fieldtype}}" ng-change="updateForm()" />
  </script>

在我的指令链接函数中,我得到了模板并显示为

 var tmpUrl=$templateCache.get(scope.template);
  elm.html(tmpUrl);
  $compile(elm.contents())(scope);

显然我在这里做错了,但我不知道是什么。

先编译,然后用新的html替换element:

    var tmpUrl=$templateCache.get(scope.template);  
    var compiledContents = $compile(elm.contents())(scope);
    // here i'm not sure about the html method
    elm.html(compiledContents); 
    // maybe you have to use 
    // elm.replaceWith(compiledContents[0])

我有类似的问题,但我使用replace ...您可能要尝试:

var tmpUrl=$angular.element($templateCache.get(scope.template));
elm.append(tmpUrl);
$compile(tmpUrl)(scope);

要么

var tmpUrl=$angular.element($templateCache.get(scope.template));
elm.append(tmpUrl);
$compile(elm)(scope);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM