Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于切换布尔值的角度函数_Javascript_Angularjs_Function_Boolean - Fatal编程技术网

Javascript 用于切换布尔值的角度函数

Javascript 用于切换布尔值的角度函数,javascript,angularjs,function,boolean,Javascript,Angularjs,Function,Boolean,我似乎遇到了一个非常简单的问题,但似乎找不到解决方案 我正在尝试将一个应用程序从vanilla JS转换为angular框架。以前,我的程序有一个对象数组,点击一个按钮会触发一个函数,该函数只会在一个对象的布尔值之间切换true或false。值为“true”的对象将被过滤掉,并显示在页面的下方 功能是 function addRepair(here, needed) { possibleRepairs[here].isNeeded = needed; var filteredAr

我似乎遇到了一个非常简单的问题,但似乎找不到解决方案

我正在尝试将一个应用程序从vanilla JS转换为angular框架。以前,我的程序有一个对象数组,点击一个按钮会触发一个函数,该函数只会在一个对象的布尔值之间切换true或false。值为“true”的对象将被过滤掉,并显示在页面的下方

功能是

function addRepair(here, needed) {
    possibleRepairs[here].isNeeded = needed;
    var filteredArray = possibleRepairs.filter(ind => ind.isNeeded).map(ind => ind.area + " " + ind.repair).join("\<br\>");
    document.getElementById('repairsGoHere').innerHTML = filteredArray;
}
在app.component.html中,我创建了一个按钮,用来进行切换

<button type="button" onclick="addRepair('0', true);">Out of true</button>
稍后页面将显示数据,以便

<div class="col-md-8" id="repairsGoHere" ng-repeat="inst in repairList | filter: {isNeeded:true}">
    <p>{{ inst.area }}</p>
</div>

{{inst.area}

关于如何编写函数以使其执行我想要的操作,有什么建议吗?或者我应该以完全不同的方式来处理这个问题

谢谢你的帮助


Evan

在这里得到一些回复后,你们都帮我弄明白了-我用Angular6编码,没有意识到ng repeat来自AngularJS时代。Ang 6没有相同的过滤器功能,因此我需要找出如何实现我所寻求的相同结果。感谢所有的投入

我不确定您正在使用的angular的哪个版本,但是imo
onclick=“addRepair('0',true);”
应该会给您一个关于不将字符串用作事件处理程序的错误+
addRepair
处理程序可能不知道,并且不会触发摘要循环。长话短说:使用
ng点击
而不是
onclick
function addRepair(here, needed) {
    repairList[here].isNeeded = needed;
}
<div class="col-md-8" id="repairsGoHere" ng-repeat="inst in repairList | filter: {isNeeded:true}">
    <p>{{ inst.area }}</p>
</div>