gpt4 book ai didi

javascript - 如何在 标签内执行 ng-repeat

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:03:17 26 4
gpt4 key购买 nike

我想在 <head> 中做一个 ng-repeat页面以枚举开放图元标记。但是,我不确定如何完成,因为 <head> 中似乎允许使用标签包含标签。

如果我简单地添加一个 <div>包装器就像我经常用 ng-repeat 做的那样,浏览器将它从 <head> 中删除向下进入 <body> .

我考虑过创建我自己的什么都不做的指令来允许我做这样的事情

<custom-repeat-wrapper ng-repeat="entry in entries">
<meta property="entry.key" content="entry.content"/>
</custom-repeat-wrapper>

我认为这行得通,但据我所知,浏览器可能会将其降低到 <body>

我想我可能会编写自己的指令,使其工作方式类似于 ng-repeat,但不需要包装器,而是复制它所在的标签。

在我走这条路之前,有人对更清洁的解决方案有任何其他建议吗?

最佳答案

您必须在 html 标记中声明 Angular 应用程序并在 meta 标记内使用 ng-repeat,如下所示:

<html ng-app="myApp">
<head ng-controller="headController">
<meta ng-repeat="entry in entries" property ="{{entry.key}}" content="{{entry.content}}">
</head>
</html>

和 Controller :

angular.module('myApp', [])
.controller('headController', function($scope) {
$scope.entries = [{
key: 'key1',
content: 'content1'
}, {
key: 'key2',
content: 'content2'
}, ];

})

这是一个有效的 plunkr:

http://plnkr.co/edit/ztCTB4mhvyou4ccKVk0u?p=preview

关于javascript - 如何在 <head> 标签内执行 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31057776/

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