2016-09-09 37 views
3

我有transclude文字指令,我需要把它裏面的佔位符AngularJS:把NG-transclude到一個變量(NG-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> 
+0

請提供您的模板'my-dialog.html' – Hornth

回答