虽然这个答案可能很简单,但我似乎陷入困境。作为Angular 2的初学者,我尝试了{},[]和()括号的所有可能组合来实现以下目的:
<button (click)="this.action">Click me</button>
其中:
this.action = "clickMe()"
即。它是一个字符串,是该组件中应该在单击时执行的方法的名称。
有什么想法吗?
答案 0 :(得分:14)
您可以使用方括号语法,例如
{
"query":{
"count":1,
"created":"2016-12-17T10:53:58Z",
"lang":"en-GB",
"diagnostics":{+}, // collapsed
"results":{
"quote":{
"symbol":"IBM",
"Ask":null, <---- NULL
"AverageDailyVolume":"3605490",
"Bid":null, <---- NULL
"AskRealtime":null,
"BidRealtime":null,
"BookValue":"17.89",
"Change_PercentChange":"-1.89 - -1.12%",
"Change":"-1.89",
"Commission":null,
"Currency":"USD",
"ChangeRealtime":null,
"AfterHoursChangeRealtime":null,
"DividendShare":"5.60",
"LastTradeDate":"12/16/2016",
"TradeDate":null,
"EarningsShare":"12.27",
"ErrorIndicationreturnedforsymbolchangedinvalid":null,
"EPSEstimateCurrentYear":"13.50",
"EPSEstimateNextYear":"13.90",
"EPSEstimateNextQuarter":"2.52",
"DaysLow":"166.13",
"DaysHigh":"169.11",
"YearLow":"116.90",
"YearHigh":"169.95",
"HoldingsGainPercent":null,
"AnnualizedGain":null,
"HoldingsGain":null,
"HoldingsGainPercentRealtime":null,
"HoldingsGainRealtime":null,
"MoreInfo":null,
"OrderBookRealtime":null,
"MarketCapitalization":"157.97B",
"MarketCapRealtime":null,
"EBITDA":"17.54B",
"ChangeFromYearLow":"49.23",
"PercentChangeFromYearLow":"+42.11%",
"LastTradeRealtimeWithTime":null,
"ChangePercentRealtime":null,
"ChangeFromYearHigh":"-3.82",
"PercebtChangeFromYearHigh":"-2.25%",
"LastTradeWithTime":"1:09pm - <b>166.13</b>",
"LastTradePriceOnly":"166.13",
"HighLimit":null,
"LowLimit":null,
"DaysRange":"166.13 - 169.11",
"DaysRangeRealtime":null,
"FiftydayMovingAverage":"160.02",
"TwoHundreddayMovingAverage":"157.25",
"ChangeFromTwoHundreddayMovingAverage":"8.88",
"PercentChangeFromTwoHundreddayMovingAverage":"+5.65%",
"ChangeFromFiftydayMovingAverage":"6.11",
"PercentChangeFromFiftydayMovingAverage":"+3.82%",
"Name":"International Business Machines",
"Notes":null,
"Open":"168.97",
"PreviousClose":"168.02",
"PricePaid":null,
"ChangeinPercent":"-1.12%",
"PriceSales":"1.99",
"PriceBook":"9.39",
"ExDividendDate":"11/8/2016",
"PERatio":"13.54",
"DividendPayDate":"12/10/2016",
"PERatioRealtime":null,
"PEGRatio":"4.37",
"PriceEPSEstimateCurrentYear":"12.31",
"PriceEPSEstimateNextYear":"11.95",
"Symbol":"IBM",
"SharesOwned":null,
"ShortRatio":"6.77",
"LastTradeTime":"1:09pm",
"TickerTrend":null,
"OneyrTargetPrice":"156.62",
"Volume":"3524102",
"HoldingsValue":null,
"HoldingsValueRealtime":null,
"YearRange":"116.90 - 169.95",
"DaysValueChange":null,
"DaysValueChangeRealtime":null,
"StockExchange":"NYQ",
"DividendYield":"3.36",
"PercentChange":"-1.12%"
}
}
}
}
,其中
(click)="this[action]()"