Javascript 如何根据bash脚本的输出在angular页面中分配toggle按钮(ngx toggle)的值?
我有一个有角度的页面,其中有几个切换按钮。我必须根据bash脚本的输出来确定它们的状态。我正在使用ngx切换。现在,这些切换按钮显示JMS适配器是否在不同的服务器上运行。我必须从服务器获取该状态Javascript 如何根据bash脚本的输出在angular页面中分配toggle按钮(ngx toggle)的值?,javascript,angular,Javascript,Angular,我有一个有角度的页面,其中有几个切换按钮。我必须根据bash脚本的输出来确定它们的状态。我正在使用ngx切换。现在,这些切换按钮显示JMS适配器是否在不同的服务器上运行。我必须从服务器获取该状态 <ngx-toggle id="devBase" [value]=""></ngx-toggle> 到目前为止,我一直试图从文本文件中读取状态,但无法更新切换按钮的值 readTextFile(file) { let rawFile = new XMLHttpRequest
<ngx-toggle id="devBase" [value]=""></ngx-toggle>
到目前为止,我一直试图从文本文件中读取状态,但无法更新切换按钮的值
readTextFile(file) {
let rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
let allText = rawFile.responseText;
let lines = allText.split("\n");
let devBase: boolean;
for (let line = 0; line < lines.length; line++) {
if (lines[line].trim() == "devBase=1") {
console.log(devBase);
devBase = true;
}
if (lines[line].trim() == "devBase=0") {
console.log(devBase);
devBase = false;
}
}
}
}
}
rawFile.send(null);
readTextFile(文件){
让rawFile=newXMLHttpRequest();
打开(“获取”,文件,错误);
rawFile.onreadystatechange=函数(){
if(rawFile.readyState==4){
if(rawFile.status==200 | | rawFile.status==0){
让allText=rawFile.responseText;
让line=allText.split(“\n”);
设devBase:boolean;
for(让line=0;line
}
当我使用[(value)]=“devBase”时,它无法处理。双向绑定正在工作。因此,html代码将是
它之前不起作用的原因是devBase是在我的ts文件的函数中定义的。我从函数返回了这个值,并将其放入一个通用变量中
readTextFile(file) {
let rawFile = new XMLHttpRequest();
let lines;
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
let allText = rawFile.responseText;
lines = allText.split("\n");
}
}
}
rawFile.send(null);
return lines;
}
在这个功能之外
lines: string[];
this.lines = this.readTextFile("http://orapoc06:8087/JavaBridgeTemplate621/dist/assets/files/status.txt");
现在还不清楚你在问什么,为什么要在你有时间的时候使用AJAX呢?使用Angular或移除标记。我还删除了您的bash标记,因为它与bash脚本无关。@trichetriche感谢您的编辑。我从来没有真正提到过AJAX。我想从参数中更新切换按钮的状态,比如devBase。它现在正在工作。我会补充一个答案。