1

i have a div having replace-with custom directive.

 <div class="timeline" layout="row" ng-repeat="event in ::vm.events">
     <div replace-with='{{event.content}}'></div>
</div>

This is my directive:

(function () {
    'use strict';

    angular
        .module('app')
        .directive('replaceWith', replaceWith);

    /* @ngInject */
    function replaceWith() {
        // Usage:
        //
        // Creates:
        //
        var directive = {
            link: link,
            restrict: 'A'
        };
        return directive;

        function link(scope, element, attrs) {
            attrs.$observe('replaceWith', function (value) {
                if (value) {
                    element.replaceWith(angular.isUndefined(value) ? '' : value);
                }
            });
        }
    }
})();

My Controller from where i am getting content data:

 vm.templateUrl = "scripts/controllers/sample.content.html";
 vm.events = [{
            title: 'Title1',
            subtitle: '',
            date: '6/6/2016',
            image: 'assets/avatar-5.png',
            content: '<div ng-include="vm.templateUrl"></div>',
            palette: ''
        }]

Here my div with replace-with attribute is not getting replaced with ng-include template.but when i hard code my content data like content:<p>Sample Data</p> it's working. can someone please help me with this.

Venkat
  • 551
  • 6
  • 17

1 Answers1

0

One approach is to use the templateURL property of the directive and make it dynamic, as described in the top answer to this question:

Angular.js directive dynamic templateURL

Community
  • 1
  • 1
Larry Turtis
  • 1,907
  • 13
  • 26