gpt4 book ai didi

javascript - ng-transclude 在模板 AngularJS 中不起作用

转载 作者:行者123 更新时间:2023-11-28 04:19:36 24 4
gpt4 key购买 nike

抱歉,如果我在这里遗漏了一些愚蠢的东西,但我真的尝试了各种组合来使这段代码工作,但没有成功。

我正在从 Recipes with AngularJS 学习 AngularjS 中的 directive 但卡在这段代码 -

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

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

PLNKR CODE

作为一个整体的代码 -

<!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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com