我有一些布尔变量,可以是true或false,基于该值,我必须在HTML中显示一些元素,如下所示:
<p *ngif=isOwner>Test</p>
问题是我必须要隐藏元素值是false但显示元素值是true:
this.storage.get('User').then((val) => {
this.isOwner = val.Owner.IsOwner;
});
在Angular 2中这样做的正确方法是什么,只是在HTML中,值总是存在,并且会是真还是假?
答案 0 :(得分:3)
只需反转条件的布尔值:
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from IPython.display import display
matplotlib.style.use('ggplot')
file = r'C:\Users\G01024822\Desktop\products.xlsx'
sheet = r'store_data'
data = pd.read_excel(file,sheetname=sheet,na_values='')
quarters = ['2018 Q1','2018 Q2','2018 Q3','2018 Q4','2019 Q1','2019 Q2','2019 Q3','2019 Q4','2020 Q1','2020 Q2','2020 Q3','2020 Q4']
categories = ['Windows','Office','Adobe']
stores = data['store'].unique().tolist()
mydata = {}
plandata = {}
for store in stores:
transaction = data[data['Store']==store]
for category in categories:
frame = transaction[transaction['Category']==category]
cycle = {}
if frame.shape[0] != 0:
for quarter in quarters:
temp = frame[frame['License_ends']==quarter]
out_of_licence = temp['Item'].count()
cycle[quarter] = out_of_licence
else:
pass
mydata[category] = cycle
df = pd.DataFrame.from_dict(mydata,orient='index')
df
HTML
export class AppComponent {
public isOwner: boolean = true;
toggleIsOwner() {
this.isOwner = !this.isOwner;
}
}
<button (click)="toggleIsOwner()">show/hide</button>
<p *ngIf="isOwner">Hello World!</p>
是一个布尔值。 *ngIf
的工作方式是,当表达式为true时,元素将插入DOM中,当表达式为false时,元素将从DOM中删除。