如何在<head>标签内进行ng-repeat

Dav*_*idA 3 javascript angularjs

我想在<head>页面中进行ng-repeat 以枚举开放图形元标记.但是,我不确定如何完成,因为似乎允许<head>的标签包含标签.

如果我只是<div>像我经常使用ng-repeat那样添加一个包装器,那么浏览器会将其从<head>下降到下方<body>.

我考虑创建自己的do-nothing指令,允许我做这样的事情

<custom-repeat-wrapper ng-repeat="entry in entries">
  <meta property="entry.key" content="entry.content"/>
</custom-repeat-wrapper>
Run Code Online (Sandbox Code Playgroud)

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

我想我可以编写自己的指令,sorta的工作方式与ng-repeat类似,但不需要包装器,而是复制它所放置的标签.

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

yve*_*era 5

您必须在html标记中声明angular app并在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>
Run Code Online (Sandbox Code Playgroud)

和控制器:

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

  })
Run Code Online (Sandbox Code Playgroud)

这是一个工作的plunkr:

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