How to make template without ng-repeat and pass data to $scope with angular-drag-and-drop-lists?

▼魔方 西西 提交于 2019-12-05 14:29:33
Paul Sweatte

How to build my own HTML template without ng-repeat

Use $templateCache and a for loop as an alternative:

var app = angular.module('foo', []);


function bop(model, data)
  {
  return data ? model : 'foo';
  }

function baz()
  {
  return bop;
  }

function foo($templateCache)
  {
  var i = 0, len = 5, bar = "";
  
  for (i; i < len; i++)
  	{
    bar = bar.concat("<li>",i,"<p ng-include=\u0022'foo'\u0022></p></li>");
    }
  
  $templateCache.put('listContent', bar);
  }

angular.module('foo').filter('baz', baz);
app.run(foo);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="foo">
  <script type="text/ng-template" id="foo">
    <span>hi</span>
  </script>
  <input ng-model="dude">
  <ul ng-include="'listContent' | baz:dude"></ul>
</div>

References

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!