Search code examples
javascriptangularjsangularjs-ng-transclude

AngularJS: Putting ng-transclude into a variable (ng-transclude to placeholder)


I Have a directive with transclude text I need to put it inside placeholder

My html

 <div ng-controller="Controller">
  <my-dialog>Hello world!</my-dialog>
  </div>

JS

(function(angular) {
  'use strict';
angular.module('docsTransclusionDirective', [])
  .controller('Controller', ['$scope', function($scope,$transclude) {
    console.log($transclude);
    $scope.name = $transclude;  // I NEED TO GET HELLO WORLD HERE

  }])
  .directive('myDialog', function() {
    return {
      restrict: 'E',
      transclude: true,
      scope: {},
      templateUrl: 'my-dialog.html'
    };
  });
})(window.angular);\

My template

<div>this should give me transcluded text {{name}}</div>

Solution

  • There are different approaches to get the transcluded content. Have a look at this question