在Ionic 3中存储所有应用程序字符串的最佳做法是什么?我应该创建一个数据提供程序并将所有字符串存储为常量吗?
答案 0 :(得分:0)
有多种方法。但我在这里选择了非常简单的方法。也就是说,只需创建一个 <!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("background.jpg");
}
pre {
background-color:rgba(0,0,0,0.2);
width: 500px;
height: 62px;
overflow: hidden;
color: #95B9C7;
border-style: solid;
border-top-color: #87CEFA;
}
</style>
</head>
<body>
<h1>Getting server updates</h1>
<pre id="result"></pre>
<script>
const result = document.getElementById("result");
if (typeof(EventSource) !== "undefined") {
var source = new EventSource("shownewattacksqli1.php");
source.onmessage = function(event) {
//Redefine node at each message event
const node = document.createTextNode(event.data + "\n");
if (count($("#result p)) >= 4) {
$("#result p:last").remove();
}
result.insertBefore("<p>"+node"</p>", result.firstChild);
};
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";
}
,如下所示。
注意:我从我的工作项目中提取了以下示例。
常量文件:
Handlers.ts
static class
像这样使用:
.TS
export class Handlers {
static BUDGET_PAGE_TOTAL_HANDLER = "budget-page-total-handler";
static NEW_PROJECT_PAGE_BUDGET_HANDLER = "new-project-page-budget-handler";
static HOME_PAGE_TRANSACTION_HANDLER = "home-page-transaction-handler";
}