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
ng repeat内的html按钮不工作_Html_Angularjs_Onclick - Fatal编程技术网

ng repeat内的html按钮不工作

ng repeat内的html按钮不工作,html,angularjs,onclick,Html,Angularjs,Onclick,我正在尝试导入一个客户列表,我想进入一个个性化的客户页面,其中包含有关客户的特定信息(使用showit函数)。我目前有: <table ng-controller="patientsCtrl" class="table-responsive" class="fixed"> <thead> <th>ID</th> <th>Name&l

我正在尝试导入一个客户列表,我想进入一个个性化的客户页面,其中包含有关客户的特定信息(使用showit函数)。我目前有:

<table ng-controller="patientsCtrl" class="table-responsive" class="fixed">                     
        <thead>
            <th>ID</th>
            <th>Name</th>
            <th>Policy Nr</th>
            <th>Pol. Type</th>
            <th>Check</th>
        </thead>
        <tbody>
            <tr ng-repeat="p in patients | orderBy:'patID'">
            <td>{{ p.patID }}</td>
            <td>{{ p.name }}</td>
            <td>{{ p.policy_number }}</td>
            <td>{{ p.policy_type }}</td>
            <td> <button ng-click="showit(p.name)">check</button> </td>
        </tbody>
</table>

身份证件
名称
保单编号
波尔。类型
检查
{{p.patID}}
{{p.name}}
{{p.policy_number}
{p.policy_type}
检查
只要假装它是写的
检查
。该按钮在表格内时不工作(功能阶段I将在稍后实施)

你有一个范围问题。该按钮在表内工作,但由于作用域层次结构的原因,数据未进入表外

<div ng-controller="patientsCtrl">
    <p>{{vari}}</p>
    <table class="table-responsive" class="fixed">                     
        <thead>
            <th>ID</th>
            <th>Name</th>
            <th>Policy Nr</th>
            <th>Pol. Type</th>
            <th>Check</th>
        </thead>
        <tbody>
            <tr ng-repeat="p in patients | orderBy:'patID'">
            <td>{{ p.patID }}</td>
            <td>{{ p.name }}</td>
            <td>{{ p.policy_number }}</td>
            <td>{{ p.policy_type }}</td>
            <td> <button ng-click="$parent.vari=true">check</button> </td>
        </tbody>
    </table>
    <p>{{vari}}</p>
</div>

{{vari}}

身份证件 名称 保单编号 波尔。类型 检查 {{p.patID}} {{p.name}} {{p.policy_number} {p.policy_type} 检查 {{vari}}

ng repeat
为集合中的每个项目创建范围。要将数据放入控制器的作用域,请使用
$parent

从文档中:

ngRepeat
指令对集合中的每个项目实例化一次模板。每个模板实例都有自己的作用域,其中给定的循环变量设置为当前集合项,
$index
设置为项索引或键


--

showit
是在作用域上声明的函数吗?控制器中的函数名应该是$scope.showit=function(name){…},如果您使用$scope当然。showit是在js文件上声明的函数。但我也尝试过更简单的事情,比如改变一个变量值,但它不起作用。我有另一个按钮,在桌子外面检查,但不起作用inside@MariaP. 如果它在js文件中,而不在$scope上,那么您需要使用onclick=“showit(p.name)”。当您使用ng click时,必须在控制器的scopeworking上定义函数