简体   繁体   English

如何创建一个角度的HTML模块

[英]How to create an HTML module angular

Learning HTML/Angular. 学习HTML / Angular。

I have a bunch of HTML code that I want to be re-usable. 我有一堆想要重新使用的HTML代码。 Basically I write it once and modify the same code base, then just insert the dynamic data using Angular. 基本上,我只编写一次并修改相同的代码库,然后仅使用Angular插入动态数据。

My question is - How do I create re-usable HTML code that can be injected into a page using Angular? 我的问题是-如何创建可重复使用的HTML代码,这些代码可以使用Angular注入到页面中?

For instance, lets say I am an app developer and want to showcase 25 apps on the same page each with their own HTML component (not just a bunch of images). 例如,假设我是一名应用程序开发人员,并希望在同一页面上展示25个应用程序,每个应用程序都具有自己的HTML组件(而不仅仅是一堆图像)。 Rather than copying the HTML 25 times I would just like to inject that HTML snippet via some angular command, then insert the text into the corresponding divs etc. I need to stick with Angular/HTML (no other frameworks) 与其复制HTML 25次,不如我想通过一些angular命令注入HTML代码段,然后将文本插入相应的div等。我需要坚持使用Angular / HTML(没有其他框架)

Or is there a better way? 或者,还有更好的方法?

(look at the image for reference - imagine inserting that layout 25 times without duplicating code) (查看该图像以供参考-想象一下在不复制代码的情况下将该布局插入25次)

I have tried this using ng-repeat but when I do so it throws the repeating items in the same spot on top of each other. 我已经尝试使用ng-repeat进行此操作,但是当我这样做时,它将重复的项目相互放在同一位置。 I was hoping that for every div that is repeated it would put it underneath the other div. 我希望每个重复的div都可以放在另一个div的下面。

<div id="apps" ng-controller="MyApps">
    <div id="appsection" ng-repeat="app in applist">
      <img class="rightappimg" src={{app.img}} />
      <strong class="appbannertext">{{app.firstLine}}</strong>
      <strong class="appbannertextsubtitle">{{app.secondLine}}</strong>
      <strong class="appbannertextsubtitlesmall"><span class="ios">iOS, iPhone, iPad</span> & <span class="android"> Android</span></strong>
      <strong class="appbannerdescriptiontitle">{{app.fourthLine}}</strong>
      <p class="appbannerdescription">{{app.fifthLine}}</p>
    </div>
  </div>

交叠

在此处输入图片说明

Ok the answer was to us ng-repeat as such: 好的,答案是这样的ng-repeat:

<div id="apps" ng-controller="MyApps">
<div id="appsection" ng-repeat="app in applist">
  <img class="rightappimg" src={{app.img}} />
  <strong class="appbannertext">{{app.firstLine}}</strong>
  <strong class="appbannertextsubtitle">{{app.secondLine}}</strong>
  <strong class="appbannertextsubtitlesmall"><span class="ios">iOS, iPhone, iPad</span> & <span class="android"> Android</span></strong>
  <strong class="appbannerdescriptiontitle">{{app.fourthLine}}</strong>
  <p class="appbannerdescription">{{app.fifthLine}}</p>
</div>

And then simply to specify a min-height in the div id in the CSS file so the items wouldn't overlap each other. 然后只需在CSS文件的div ID中指定一个最小高度,这样项目之间就不会相互重叠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM