博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AngularJS] Directive with Transcluded Elements
阅读量:4876 次
发布时间:2019-06-11

本文共 2515 字,大约阅读时间需要 8 分钟。

Create a wrapWith directive using advanced transclusion techniques.

transclude - compile the content of the element and make it available to the directive. Typically used with ngTransclude. The advantage of transclusion is that the linking function receives a transclusion function which is pre-bound to the correct scope. In a typical setup the widget creates an isolate scope, but the transclusion is not a child, but a sibling of the isolate scope. This makes it possible for the widget to have private state, and the transclusion to be bound to the parent (pre-isolate) scope.

true - transclude the content of the directive. (replace the whole stuff)

'element' - transclude the whole element including any directives defined at lower priority. (append to the dom)

See more: 

 

    Egghead.io    
      
var egghead = angular.module("egghead", []);egghead.controller("AppCtrl", function () {    var app = this;    app.people = [{"firstName":"Sonia","lastName":"Hodges"},{"firstName":"Benedict","lastName":"Morrow"},{"firstName":"Keegan","lastName":"Fields"},{"firstName":"Jade","lastName":"Martinez"},{"firstName":"Jaquelyn","lastName":"Suarez"},{"firstName":"Leo","lastName":"Hughes"},{"firstName":"Skyler","lastName":"Sharp"},{"firstName":"Genevieve","lastName":"Villarreal"},{"firstName":"Beau","lastName":"Hendrix"},{"firstName":"Lara","lastName":"Howard"},{"firstName":"Jonah","lastName":"Crawford"},{"firstName":"Kendall","lastName":"Lane"},{"firstName":"Kimberly","lastName":"Mcclain"},{"firstName":"Ingrid","lastName":"Salinas"},{"firstName":"Moses","lastName":"Mcpherson"},{"firstName":"Britanney","lastName":"Sweeney"},{"firstName":"Patricia","lastName":"Perez"},{"firstName":"Roth","lastName":"Heath"},{"firstName":"Nora","lastName":"Osborne"},{"firstName":"Giacomo","lastName":"Shepard"}]});egghead.directive("wrapWith", function ($templateCache) {    return {        transclude: 'element',        link: function (scope, element, attrs, ctrl, transclude) {            var template = $templateCache.get(attrs.wrapWith);            console.log(template);            var templateElement = angular.element(template);            console.log(element);            transclude(scope, function (clone) {                element.after(templateElement.append(clone));            })        }    }});egghead.directive("cgForm", function ($templateCache) {    return {        restrict: "EA",        templateUrl: "form-info"    }});

 

 

result: 

转载于:https://www.cnblogs.com/Answer1215/p/4177319.html

你可能感兴趣的文章
Java动手动脑第四讲课堂作业
查看>>
PowerDesigner 数据建模技术视频教程
查看>>
Webpack 开发服务器代理设置解决跨域问题
查看>>
Solr 15 - Solr添加和更新索引的过程 (文档的路由细节)
查看>>
DOS命令
查看>>
Oracle merge基本使用
查看>>
03-树1 树的同构
查看>>
第九周周记
查看>>
AdvStringGrid入门使用
查看>>
C#图像处理——ImageProcessor
查看>>
NOI2004 降雨量
查看>>
WPF的TextBox水印效果详解
查看>>
oracle启动服务和监听命令
查看>>
毒药和酒
查看>>
浅谈linux内核中内存分配函数
查看>>
走近SpringBoot
查看>>
java timer 使用:
查看>>
Lazyr.js – 延迟加载图片(Lazy Loading)
查看>>
二叉树相关题目8/24
查看>>
我的Android进阶之旅------>Android安全退出应用程序的几种方式
查看>>