如何在<头部>标签

How to do an ng-repeat inside the <head> tag

本文关键字:头部 gt 标签 lt      更新时间:2023-09-26

我想在页面的<head>中执行ng重复,以便枚举打开的图元标记。然而,我不确定如何实现,因为<head>中允许的标签似乎包含标签。

如果我像经常使用ng repeat那样简单地添加一个<div>包装器,浏览器会将其从<head>向下压缩到<body>

我已经考虑创建我自己的什么都不做的指令,允许我做这样的

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

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

我想我可能会写我自己的指令,sorta的工作原理类似于ng-reeat,但不需要包装器,而是复制它所放的标签。

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

您必须在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>

控制器:

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