Angular2在解析值

时间:2017-03-03 05:35:01

标签: angular

我有一个Ionic2模板,其中img src来自json。渲染代码是

<img src="questionSetChosen[currentQuestion]?.questiondata.questionImgUrl" alt="" *ngIf="questionSetChosen[currentQuestion]?.questiondata.questionImgUrl != 'NA' "/>

JSON是

"questiondata": {
                    "questionImgUrl": "NA",
                    "userChoice": "Z",
                    "isAnswered": "no",
                    "isCorrect": "NA",
                    "questionid": "tq0ql9ar50qg",
                    "explanation": "<p>Capsule Endoscopy is not suiëtable for patients with strictures.</p>",
                    "question": "Capsule Endoscopy-False statement is",
                    "reference": "Bailey and Love 26th Edition P/205"
                },

尽管使用Elvis运算符和* ngIf angular2在页面加载时闪烁空白img一小段时间。

我该如何防止这种情况。

1 个答案:

答案 0 :(得分:0)

library(rvest)

kk<-read_html("http://www.dnr.state.mn.us/lakefind/showreport.html?downum=56003100")

node <- "table.table_colors:nth-child(1) > tbody:nth-child(1)"

html_table(node, fill=TRUE)

head(kk)

如果将其强制为null,则会将其评估为true( *ngIf="questionSetChosen[currentQuestion]?.questiondata.questionImgUrl != 'NA' " != null为真)。

您希望先将其短路并先进行空值检查以防止图像闪烁。