抱歉,如果我在这里遗漏了一些愚蠢的东西,但我真的尝试了各种组合来使这段代码工作,但没有成功。
我正在从 Recipes with AngularJS
学习 AngularjS
中的 directive
但卡在这段代码 -
https://github.com/fdietz/recipes-with-angular-js-examples/tree/master/chapter3/recipe4
我相信它应该在Hello World p
文本之前打印Heading。但它不会来。让我知道我的代码中缺少什么 -
作为一个整体的代码 -
<!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>
最佳答案
检查“div”之前的第一个“h3”
template: "<h3>Heading</h3><div ng-transclude></div>"
关于javascript - ng-transclude 在模板 AngularJS 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25725787/