ng-transclude不在模板AngularJS中工作

Tri*_*der 1 html javascript angularjs transclusion angularjs-directive

对不起,如果我在这里丢失了一些愚蠢的东西,但我真的尝试了各种组合来使这个代码工作,但没有运气.

我在学习directiveAngularjS,从Recipes with AngularJS而停留在这个码-

https://github.com/fdietz/recipes-with-angular-js-examples/tree/master/chapter3/recipe4

我相信它应该在Hello World文本之前打印Heading.但它不会来.让我知道我的代码中缺少的内容 - p

PLNKR代码

代码整体 -

<!doctype html>
<html lang="en" ng-app="myApp">
<head>
    <meta charset="utf-8" />
    <title>Directive Example</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
    <script>
        var myApp = angular.module("myApp", []);

        myApp.directive("myWidget", function(){
            return {
                restrict: "E",
                transclude: true,
                template: "<div ng-transclude><h3>Heading</h3></div>"
            };
        });
    </script>
</head>
<body>
    <my-widget>
        <p>Hello World!!</p>
    </my-widget>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Noy*_*las 6

检查"div"之前的第一个"h3"

template: "<h3>Heading</h3><div ng-transclude></div>"
Run Code Online (Sandbox Code Playgroud)