transclusion

Get original transcluded content within angular directive

泄露秘密 提交于 2019-12-03 06:50:00
问题 My goal is to create an editable directive that allows a user to edit HTML of any element to which the attribute is attached (see Plunker: http://plnkr.co/edit/nIrr9Lu0PZN2PdnhQOC6) This almost works except I can't get the original raw HTML of the transcluded content to initialize the text area. I can get the text of it from clone.text() , but that's missing the HTML tags like <H1> , <div> , etc. so clicking apply with no edits is not idempotent. The method clone.html() throws an error,

AngularJS : ng-controller on directive does not work on transcluded elements within directive

只谈情不闲聊 提交于 2019-12-03 05:13:29
问题 Here is my script: angular.module('MyApp',[]) .directive('mySalutation',function(){ return { restrict:'E', scope:true, replace:true, transclude:true, template:'<div>Hello<div ng-transclude></div></div>', link:function($scope,$element,$attrs){ } }; }) .controller('SalutationController',['$scope',function($scope){ $scope.target = "StackOverflow"; }]) and the html: <body ng-app="MyApp"> <my-salutation ng-controller="SalutationController"> <strong>{{target}}</strong> </my-salutation> </body> The

Get original transcluded content within angular directive

前提是你 提交于 2019-12-02 20:28:11
My goal is to create an editable directive that allows a user to edit HTML of any element to which the attribute is attached (see Plunker: http://plnkr.co/edit/nIrr9Lu0PZN2PdnhQOC6 ) This almost works except I can't get the original raw HTML of the transcluded content to initialize the text area. I can get the text of it from clone.text() , but that's missing the HTML tags like <H1> , <div> , etc. so clicking apply with no edits is not idempotent. The method clone.html() throws an error, Cannot read property 'childNodes' of undefined app.directive("editable", function($rootScope) { return {

Custom template(transclusion without ng-content) for list component in Angular2

二次信任 提交于 2019-11-27 23:19:11
I have a list component which shows only names. list component should be able to take custom template which will be given by user. List Component import {Component } from 'angular2/core'; @Component({ selector: 'my-list', template: `<p>This is List</p> <ul> <li *ngFor="#i of data"><div class='listItem'>{{i.name}}</div></li> </ul>` }) export class MyList implements OnInit{ data: Array<any> = [{name: 'John', age: 26},{name: 'Kevin', age: 26}, {name:'Simmons', age:26}]; } My Requirement <my-list> <div>{{i.name}}-{{i.age}}</div> //user should be able to provide custom template like this </my-list>

React.js: Wrapping one component into another

眉间皱痕 提交于 2019-11-27 16:40:42
Many template languages have "slots" or "yield" statements, that allow to do some sort of inversion of control to wrap one template inside of another. Angular has "transclude" option . Rails has yield statement . If React.js had yield statement, it would look like this: var Wrapper = React.createClass({ render: function() { return ( <div className="wrapper"> before <yield/> after </div> ); } }); var Main = React.createClass({ render: function() { return ( <Wrapper><h1>content</h1></Wrapper> ); } }); Desired output: <div class="wrapper"> before <h1>content</h1> after </div> Alas, React.js doesn

How to check whether ng-content exists

狂风中的少年 提交于 2019-11-27 12:56:34
问题 Suppose i have simple Bootstrap panel component with multiple transclusion slots. Template example: <div class="panel panel-default"> <div class="panel-heading"> <ng-content select="my-panel-heading"></ng-content> </div> <div class="panel-body"> <ng-content select="my-panel-content"></ng-content> </div> </div> I want to make panel-heading optional. How do i hide <div class="panel-heading"> element, if there is no content provided for <ng-content select="my-panel-heading"></ng-content> 回答1: If

What is ng-transclude?

若如初见. 提交于 2019-11-27 09:58:13
I have seen a number of questions on StackOverflow discussing ng-transclude, but none explaining in layman's terms what it is. The description in the documentation is as follows: Directive that marks the insertion point for the transcluded DOM of the nearest parent directive that uses transclusion. This is fairly confusing. Would someone be able to explain in simple terms what ng-transclude is intended to do and where it might be used? Transclude is a setting to tell angular to capture everything that is put inside the directive in the markup and use it somewhere (Where actually the ng

How can I include a YAML file inside another?

孤人 提交于 2019-11-26 21:42:43
So I have two YAML files, "A" and "B" and I want the contents of A to be inserted inside B, either spliced into the existing data structure, like an array, or as a child of an element, like the value for a certain hash key. Is this possible at all? How? If not, any pointers to a normative reference? No, YAML does not include any kind of "import" or "include" statement. Josh Bode Your question does not ask for a Python solution, but here is one using PyYAML . PyYAML allows you to attach custom constructors (such as !include ) to the YAML loader. I've included a root directory that can be set so

React.js: Wrapping one component into another

微笑、不失礼 提交于 2019-11-26 18:43:45
问题 Many template languages have "slots" or "yield" statements, that allow to do some sort of inversion of control to wrap one template inside of another. Angular has "transclude" option. Rails has yield statement. If React.js had yield statement, it would look like this: var Wrapper = React.createClass({ render: function() { return ( <div className="wrapper"> before <yield/> after </div> ); } }); var Main = React.createClass({ render: function() { return ( <Wrapper><h1>content</h1></Wrapper> );

What is ng-transclude?

守給你的承諾、 提交于 2019-11-26 14:58:23
问题 I have seen a number of questions on StackOverflow discussing ng-transclude, but none explaining in layman's terms what it is. The description in the documentation is as follows: Directive that marks the insertion point for the transcluded DOM of the nearest parent directive that uses transclusion. This is fairly confusing. Would someone be able to explain in simple terms what ng-transclude is intended to do and where it might be used? 回答1: Transclude is a setting to tell angular to capture