Removing an item form Array


I have a little problem:

Everywhere they write this for removing an item in array:

$scope.delete = function(idx) {
   var delItem = $scope.persons[idx];

   Person.delete( {
        $scope.persons.splice(idx, 1);

but this will remove the first time 2 items. after this it will remove multiple items from scope. (from db they will not be removed)

I have the feeling that the controller gets instantiated multiple times.
I know controllers are not singletons and its possible if you do something false.

But i did look up my whole code and i don’t have added it 2 times. I add the controller at stateProvider
And i start my App with bootstrap because i need to wait for plugins to be loaded.

I did create a plunker but there i don’t have the problem -.-

you guys have a idea?


looks like i found the problem

I changed my Code to use <script id="views/person/detail.html" type="text/ng-template">
instead of using real html files.

now my first test are positiv.

so im not sure if its a bug form ui-router or ionic.

okey it did not work
still have the problem with splicing…


Maybe your click / function is triggered multiple time?

This could also happen If you including angularjs multiple times.
Maybe your are using ionic.bundle and additional to that angularjs?

Or are you using the same controller in different views in a state or parent state?

greetz, bengtler

PS: i do not have problems with splicing in my apps


angular is only included once im dont using bundle atm.
controller is only used by one view.

but what i just have found:
when i wait long enough it will only be called once.
Is it possible when the digest cycle is not done and i do an action that its triggered multiple time(method)?

btw i have around 191 watches in my views. is that too much?


WTF! 191 Oo

You should try to avoid watchers especially on the rootScope.
Most watchers can be removed by using angularjs event system:
$on, $emit, $broadcast

Maybe you can build a codepen for that?


well everything that is bind to html like with ng-bind or {{var}} will have its own watcher.
and i do not use watchers explicit they are all form the binding.

and i just have a normal list with picture and text binded.


ah okay i thought 191 explicit watchers… but a code pen would be very nice