首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular js中的Transclusion属性

angular js中的Transclusion属性
EN

Stack Overflow用户
提问于 2014-06-07 22:57:35
回答 1查看 282关注 0票数 1

我正在学习Angularjs.我被困在了tranclusion属性中,因为它混淆了me.How ng-transclude的工作?它会将dom中标记为ng-transclude的内容替换为transcluded元素(要转换的元素),还是简单地将transcluded元素附加到标记为ng-transclude的dom中?

我参考了egghead angularjs视频教程中的转换性属性https://egghead.io/lessons/angularjs-transclusion-basics

这里提到ng-transclude只是将transcluded元素附加到标记为ng-transclude的dom中,但当我尝试使用它时,它并非如此

这是我的html文件

learning.hmtl

代码语言:javascript
复制
<html ng-app="learnangular">
<head>
    <title></title>
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="learnscript.js"></script>
</head>
<body>
<div ng-controller="firstcontroller">
<custom-directive><div>This is transcluded part</div></custom-directive>
</div>
</body>
</html>

下面是我的脚本文件learnscript.js

代码语言:javascript
复制
var app=angular.module("learnangular",[]);

app.controller("firstcontroller",function($scope){
$scope.dirobject="directive object";
});

app.directive("customDirective",function(){

    return {

   restrict:"E",
   transclude:true,
   replace:false,
   template:"<input type='text' ng-model='dirobject'></input>"+
   "<div ng-transclude>{{dirobject}}</div>",

   link:function(scope,element,attr){
   }
    };
});

ng-transclude替换了dom中标记为ng-transclude的内容,为什么会这样?

EN

回答 1

Stack Overflow用户

发布于 2014-06-07 23:15:28

据我所知,now.The视频是用angular js版本1.0.x录制的,我使用的是最新版本。实际上,在最新版本中,转换后的标记完全用ng-transclude属性替换了元素的内容。在以前的版本中,转换后的标记将是appended.Thanks everyone

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24098488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档