AngularJS: ng-repeat list is not updated when a model element is spliced from the model array

后端 未结 5 2057
走了就别回头了
走了就别回头了 2020-11-27 12:42

I have two controllers and share data between them with an app.factory function.

The first controller adds a widget in the model array (pluginsDisplayed) when a link

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 13:23

    If you add a $scope.$apply(); right after $scope.pluginsDisplayed.splice(index,1); then it works.

    I am not sure why this is happening, but basically when AngularJS doesn't know that the $scope has changed, it requires to call $apply manually. I am also new to AngularJS so cannot explain this better. I need too look more into it.

    I found this awesome article that explains it quite properly. Note: I think it might be better to use ng-click (docs) rather than binding to "mousedown". I wrote a simple app here (http://avinash.me/losh, source http://github.com/hardfire/losh) based on AngularJS. It is not very clean, but it might be of help.

提交回复
热议问题