Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>NOTE: this is not my original answer but this is how I'd do this after using angular for a bit.</strong></p> <p>I would create a directive with the html template as the markup passing in the dynamic data to the directive as seen in <a href="http://jsfiddle.net/NMmyY/141/">this fiddle</a>.</p> <p>Steps/notes for this example:</p> <ol> <li>Define a directive with markup in the <code>templateUrl</code> and attribute(s) used to pass data into the directive (named <code>type</code> in this example). </li> <li>Use the directive data in the template (named <code>type</code> in this example).</li> <li>When using the directive in the markup make sure you pass in the data from the controller scope to the directive (<code>&lt;address-form type="billing"&gt;&lt;/address-form&gt;</code> (where billing is accessing an object on the controller scope).</li> <li>Note that when defining a directive the name is camel cased but when used in the markup it is lower case dash delimited (ie it's named <code>addressForm</code> in the js but <code>address-form</code> in the html). More info on this can be found in the angular docs <a href="https://docs.angularjs.org/guide/directive">here</a>.</li> </ol> <p>Here is the js:</p> <pre><code>var myApp = angular.module('myApp',[]); angular.module('myApp').directive('addressForm', function() { return { restrict: 'E', templateUrl: 'partials/addressform.html', // markup for template scope: { type: '=' // allows data to be passed into directive from controller scope } }; }); angular.module('myApp').controller('MyCtrl', function($scope) { // sample objects in the controller scope that gets passed to the directive $scope.billing = { type: 'billing type', value: 'abc' }; $scope.delivery = { type: 'delivery type', value: 'def' }; }); </code></pre> <p>With markup:</p> <pre><code>&lt;div ng-controller="MyCtrl"&gt; &lt;address-form type="billing"&gt;&lt;/address-form&gt; &lt;address-form type="delivery"&gt;&lt;/address-form&gt; &lt;/div&gt; </code></pre> <hr> <p><strong>ORIGINAL ANSWER (which is completely different than using a directive BTW).</strong></p> <p>Note: The fiddle from my original answer below doesn't appear to work anymore due to an error (but keeping it here in case it is still useful)</p> <p>There was a discussion about this on the Google Group you can <a href="https://groups.google.com/d/topic/angular/5clM0kjHXq8/discussion">see it here</a>.</p> <p>It looks like this functionality is not supported out of the box but you can use Brice's patch as described in <a href="https://groups.google.com/d/msg/angular/5clM0kjHXq8/5Wj5716_QikJ">this post</a>.</p> <p>Here is the sample code from his <a href="http://jsfiddle.net/briceburg/NMmyY/1/">jsfiddle</a>:</p> <pre><code>&lt;script id="partials/addressform.html" type="text/ng-template"&gt; partial of type {{type}}&lt;br&gt; &lt;/script&gt; &lt;div ng-controller="MyCtrl"&gt; &lt;ng-include src="'partials/addressform.html'" onInclude="type='billing'"&gt;&lt;/ng-include&gt; &lt;ng-include src="'partials/addressform.html'" onLoad="type='delivery'"&gt;&lt;/ng-include&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload