简体   繁体   English

ANGULAR 1.6-Ionic 1 | 控制器中的函数参数与ng-click传递的参数不同

[英]ANGULAR 1.6 - Ionic 1 | Function params in controller different from params passed from ng-click

I'm working on an Ionic 1 application using angular 1.6. 我正在使用angular 1.6开发Ionic 1应用程序。 I have a dynamically generated template with 4 div inputs (phone 1 & phone 1 value, phone 2 & phone 2 value, ...) generated from ng-repeat. 我有一个动态生成的模板,该模板具有从ng-repeat生成的4个div输入(电话1和电话1的值,电话2和电话2的值,...)。 Each of these div has a delete button. 每个div都有一个删除按钮。 On the ng-click, we pass to the controller some params including the current id of the phone we want to delete. 在ng-click上,我们将一些参数传递给控制器​​,其中包括我们要删除的电话的当前ID。

<button ng-click="my_delete_function(id)"></button>

So my first delete works just fine. 所以我的第一个删除工作正常。 However, on my second delete (for example : I've just deleted phone 1 and now I want to delete phone 2), the delete function in my controller keeps receiving old params. 但是,在第二次删除时(例如:我刚刚删除了电话1,现在我想删除电话2),控制器中的删除功能将继续接收旧参数。 I verified in my HTML and even if I have the correct id "2" in my ng-click, the controller still receive id "1". 我在HTML中进行了验证,即使我在ng-click中具有正确的ID“ 2”,控制器仍会收到ID“ 1”。

If I quit the view then I come back and try to delete again, the first time will again work until the next deletes where it would fail. 如果我退出视图,则返回并尝试再次删除,第一次将再次起作用,直到下一次删除将失败为止。

I've already tried 我已经试过了

<ion-view cache-view="false">
...
</ion-view>

but this doesn't change anything. 但这并没有改变任何东西。

Anyone has got any ideas on what could be happening? 有人对可能发生的事情有任何想法吗?

UPDATE 1 更新1

I cannot post my entire template, but here is a simplified version : 我无法发布整个模板,但这是一个简化的版本:

template : 模板:

<div ng-repeat="phone on phones">
<p> phone.name </p> <button ng-click="delete(phone.id)">
</div>

controller function : 控制器功能:

$scope.delete = function(id_phone){
// deleting procedure
}

This is in my controller where I receive the wrong id. 这是在控制器中我收到错误ID的地方。 The template however (my ng-click) sends the correct one. 但是,模板(我的ng-click)发送了正确的模板。

Thank you for your help 谢谢您的帮助

UPDATE 2 : PROBLEM SOLVED 更新2:解决问题

Solved my problem. 解决了我的问题。 I had "track by $index" on my ng-repeat. 我的ng-repeat上有“按$ index跟踪”。 I removed it and now everything seems ok. 我删除了它,现在一切似乎正常。

Solved my problem. 解决了我的问题。 I had "track by $index" on my ng-repeat. 我的ng-repeat上有“按$ index跟踪”。 I removed it and now everything seems ok. 我删除了它,现在一切似乎正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM