如何避免元素与Angular中的元素重叠 [英] How to avoid elements overlapping elements in Angular

查看:79
本文介绍了如何避免元素与Angular中的元素重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序基于Angular,我使用表行动态填充页面.页面下方有一个应用程序控制台,此元素的位置似乎固定.当我单击按钮添加新行时,新行与应用程序控制台重叠.如何避免这种情况.

My app is Angular based, I dynamically populate the page with table rows. There is an app-console below page, the position of this element seems to be fixed. When I click button new row is added, the new row overlaps with app-console. How to avoid this.

下面是图片和代码段.

**app.component.html**
<div>
  <button style="width:100px;" class="btn" (click)="addProduct()" >Add 
   Product</button>
.... other elements needed for table row ....
</div>
 <br>
<app-console [consoleMessages]="consoleMessages"></app-console>

**app.component.ts**


addProduct () {
    let product = JSON.parse(JSON.stringify(this.productTemplate));
    this.record['products'].push(product);//dynamically adds table row 
  }

Angular支持动态添加元素,如何避免元素重叠?

Angular supports dynamically adding elements, how do I avoid elements from overlapping?

此问题的更新:

console.component.html

<mat-tab-group class="console">
  <mat-tab class="tab" label="Console">
    <pre style="height:200px;"><code [innerHtml]="htmlCode"></code></pre>
  </mat-tab>
</mat-tab-group>

console.component.ts

import { Component, OnInit, Input } from '@angular/core';
import { highlightAuto } from 'highlight.js';
@Component({
  selector: 'app-console',
  templateUrl: './console.component.html',
  styleUrls: ['./console.component.css']
})
export class ConsoleComponent implements OnInit {

  @Input() consoleMessages = '';
  consoleHtmlMessages = '';

  constructor() { }

  ngOnInit() {
  }


  get htmlCode() {
    return highlightAuto(this.consoleMessages, ['html']).value;
  }

}

推荐答案

/* reset the html and body */
html, body {
  height: 100%;
  padding: 0;
  margin: 0;
}

.container {
  display: flex;
  height: 100%;
  flex-direction: column;
  justify-content: space-between;
}

.list, .console {
  box-sizing: border-box;
  padding: 0 1em;
  /* this scroll will keep both areas always visible */
  overflow: auto;
}

.list {
  background: #ccedff;
  flex-grow: 1;
}

.console {
  background: #eeefef;
  /* define a minumum size to your console */
  min-height: 200px;
}

<div class="container">
  <div class="list">
    <!--- // your list component... -->
  </div>
  <div class="console">
    <!--- // your console component... -->
  </div>
</div>

糟糕:此代码段似乎无法在此处正确显示,因此您可以在下面看到一个实时示例.

Obs: the snippet seems not to render correctly here, so you can see a live example below.

实时示例

这篇关于如何避免元素与Angular中的元素重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆