如果我有一个解析为String的角度表达式,我可以向该表达式添加一个条件,该条件会将额外的文本附加到该String吗?
我有:
print "Error: " + str(status)
但如果<span>{{groupType}}</span>
解析为汽车或动物,我想在字符串的末尾添加一个s。
我可以在表达式中添加条件来完成此操作吗?
答案 0 :(得分:2)
您可以在Angular表达式中使用Ternary运算符
<span>{{groupType === 'Car' || groupType === 'Animal' ? groupType + 's' : groupType}}</span>
答案 1 :(得分:2)
是的,你可以:
[DllImport("user32")]
private static extern bool GetWindowThreadProcessId(int hWnd, out int id);
for(i=0;i<2;i++)
{
oXL = new Microsoft.Office.Interop.Excel.Application();
oXL.SheetsInNewWorkbook = 1;
oXL.Visible = false;
//Get a new workbook.
oWB = (Excel.Workbook)(oXL.Workbooks.Add(Type.Missing));
oSheet = (Excel.Worksheet)oWB.Worksheets.get_Item(1);+
oSheet.Name = "Summary Report";//Change the name as per your requirment
ExcelRowsCount = 2;
for (int RowsCount = 0; RowsCount < dt.Rows.Count; RowsCount++)
{
for (int ColumnsCount = 0; ColumnsCount < dt.Columns.Count; ColumnsCount++)
{
if (RowsCount.Equals(0) && ColumnsCount.Equals(0))
oSheet.Cells[2, 1] = dt.Rows[RowsCount][ColumnsCount].ToString();
else
oSheet.Cells[ExcelRowsCount + RowsCount, ColumnsCount + 1] = dt.Rows[RowsCount][ColumnsCount].ToString();
}
oXL.Visible = false;
oXL.UserControl = false;
oXL.DisplayAlerts = false;
oXL.ActiveWorkbook.SaveAs(FileName, Excel.XlFileFormat.xlWorkbookNormal, "", "", false, false, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
oWB.Close(false, Type.Missing, Type.Missing);
oXL.Workbooks.Close();
oXL.Quit();
int ExcelID;
GetWindowThreadProcessId(oXL.Hwnd, out ExcelID);
Process XLProcess = Process.GetProcessById(ExcelID);
Marshal.ReleaseComObject(oSheet);
Marshal.ReleaseComObject(oWB);
Marshal.ReleaseComObject(oXL);
XLProcess.Kill();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
我使用<span>{{["Car", "Animal"].indexOf(groupType) >= 0 ? groupType + 's' : groupType}}</span>
的名字数组,因为它比“x或y或z”短
理想情况下,您不希望在HTML中使用此逻辑。我建议把它放在你的控制器中的一个函数中:
indexOf
然后,在您的HTML中:
$scope.getGroupType = function(type){
if(["Car", "Anumal"].indexOf(type) >= 0)
return type + 's';
return type;
};