带有动态模板和transclude的Angularjs指令

带有动态模板和transclude的Angularjs指令,angularjs,angularjs-directive,angular-directive,angularjs-ng-transclude,angular-template,Angularjs,Angularjs Directive,Angular Directive,Angularjs Ng Transclude,Angular Template,我正在尝试添加一个动态模板,但遇到了transclude问题 这是动态模板功能: var getTemplate = function(contentType){ var template = '<button style="cursor: pointer;">' + contentType + '<ng-transclude></ng-transclude></button>' return template; }

我正在尝试添加一个动态模板,但遇到了transclude问题

这是动态模板功能:

var getTemplate = function(contentType){
      var template = '<button style="cursor: pointer;">' + contentType + '<ng-transclude></ng-transclude></button>'
      return template;
    };
请看这里的完整代码

查看控制台我看到这个通知:angular.js:13920TypeError:transclude不是一个函数

结果应该包括:Go按钮

转到按钮代码:

<my-button firstname="John"><button style="cursor: pointer;"><i style="color: green;">Go</i></button></my-button>
Go
请帮我修一下

这是我使用的文档:


非常感谢。

在plunkr中找不到角度脚本的路径。切换到
,我看到错误“angular.js:13920TypeError:transclude不是一个函数…”

我已经解决了这个问题

这是新的示例代码: HTML代码:

<div ng-controller="MyCtrl">
<my-directive title="nguyen hai dang">
<button>some button</button>
<a href="#">and a link</a>
</my-directive>
</div>

一些按钮
JS代码:

var myApp = angular.module("myApp",[]);

function MyCtrl($scope) {
    $scope.log=[];
}

myApp.directive("myDirective", function(){
    return{
    restrict: "E",
    replace: true,
        transclude: true,
    scope: {
            title: "@"
          },
        template: "<div class=\"something\" ng-transclude>{{title}} </div>"
    };
});
var myApp=angular.module(“myApp”,[]);
函数MyCtrl($scope){
$scope.log=[];
}
myApp.directive(“myDirective”,function()){
返回{
限制:“E”,
替换:正确,
是的,
范围:{
标题:“@”
},
模板:“{{title}}”
};
});

检查这里的代码

你检查控制台了吗???我也面对这个问题,我用我的cdn更改了那个问题,然后我得到了正确的输出,但在控制台我得到了以下错误“模板中非法使用ngTransclude指令!没有找到需要转换的父指令。元素:”是的,这是一个错误,我已经更新了angular的新url,但这篇文章显示了错误。自那篇文章发表以来,转述已经改变了好几次;2015年的语法将无法与Angular的最新版本一起使用,而且很可能逻辑也不会是您所期望的。你应该重新思考你想要实现的目标,并在帖子中提出问题,询问如何实现你的目标,而不是如何解决一篇过时文章中的错误;除非,也就是说,您使用的angular版本与所讨论的文章完全相同,这可能不是一个好主意。。。。
var myApp = angular.module("myApp",[]);

function MyCtrl($scope) {
    $scope.log=[];
}

myApp.directive("myDirective", function(){
    return{
    restrict: "E",
    replace: true,
        transclude: true,
    scope: {
            title: "@"
          },
        template: "<div class=\"something\" ng-transclude>{{title}} </div>"
    };
});