angularjs - How to get a directive's original content when using a template? -


Looking at an instruction with a template, How could the original material get?

For example:

HTML:

  & lt; div my-directive & gt; & Lt; Input type = "text" & gt; & Lt; / Div & gt; Directive ('my directive', function () {return {template: '' app '', []): {  

& lt; Div & gt; Template & lt; / Div & gt; ', Compiled: function (element) {console.log (element.html ()); // output & lt; Div & gt; Template & lt; / Div & gt; // I & lt; How to get input type = "text" & gt ;?}};});

Since you are now It is necessary for display purpose and do not really use it with binding and other materials and it is touched by angular before you need it. You can use the property expression syntax of the template directive.

Example: -

  var content; Template: Function (Lm) {content = elm.html (); // html returns' & lt; Div & gt; Template & lt; / Div> Save; },   

Extended examples to support multiple: -

 . Directive ('myDirective', function ($ timeout) {var content = {}; var loadedDiars; return {scope: true, templates: function (elm) {loaded darts = loaded dirers · angular element (document.quire selectorsall ('[Directive]'); // LoadedDirs   ,  ADX (LM)] = LLMML (); Return '& lt; div & gt; Template & lt; div & gt; Link: Function (Scope, Element) {var idx = loaded.dirs.index ( E lement); scope.orig = content [idx]; // Remove the content [idx]; // Remove the reference of the loaded diary if (! Object.keys (content)) {loadedDirs = null;}}}}} );   

Any Jquery solutions (work for index )

 . Directive ('my directive', function ($ timeout)) {var content = {}, idx = 0; Return {scope: true, template: function (elm) {elm.idx = idx; // a moving index / element to its related index content [idx ++] = alm html // To save a element on the map returns HTML '& lt; Div & gt; Template & lt; Div & gt; & Lt; Pre & gt; {{orig}} & lt; / Pre & gt; ; & Lt; / Div & gt; & Lt; / Div & gt; '}, Link: function (area, element) {var idx = element.idx; // element scope.orig = content [idx]; // get idx property value delete content to remove content [idx]; // Remove the key if (! Object. Key (content)) {idx = 0;} // once all are loaded}}}};   



Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -