I need to use jqlite to insert the HTML for the directive, but for some reason the directive does not insert the template.
<div ng-app="docsSimpleDirective">
<div ng-controller="Controller">
<button ng-click="showCustomer($event)">click to see the customer</button>
<div>
</div>
And my app.js looks like:
angular.module('docsSimpleDirective', [])
.controller('Controller', ['$scope', function ($scope) {
$scope.customer = {
name: 'Naomi',
address: '1600 Amphitheatre'
};
$scope.showCustomer = function($event) {
angular.element($event.currentTarget).next().html("<div my-customer></div>");
};
}])
.directive('myCustomer', function () {
return {
template: 'Name: {{customer.name}} Address: {{customer.address}}'
};
});
http://jsfiddle.net/4nad43gn/
NOTE: This is just to try and recreate the situation i'm in, but the directive has to be inserted to the DOM in a similar way to the above - otherwise it will not work for my situation.