AngularJS:将ng-transclude放入变量(ng-transclude to placeholder)

时间:2016-09-09 08:38:12

标签: javascript angularjs angularjs-ng-transclude

我有一个带有transclude文本的指令我需要把它放在占位符

我的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);\

我的模板

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

1 个答案:

答案 0 :(得分:1)

获取已转换内容的方法有很多种。 Have a look at this question