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

后端 未结 5 2054
走了就别回头了
走了就别回头了 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:27

    Whenever you do some form of operation outside of AngularJS, such as doing an Ajax call with jQuery, or binding an event to an element like you have here you need to let AngularJS know to update itself. Here is the code change you need to do:

    app.directive("remove", function () {
        return function (scope, element, attrs) {
            element.bind ("mousedown", function () {
                scope.remove(element);
                scope.$apply();
            })
        };
    
    });
    
    app.directive("resize", function () {
        return function (scope, element, attrs) {
            element.bind ("mousedown", function () {
                scope.resize(element);
                scope.$apply();
            })
        };
    });
    

    Here is the documentation on it: https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$apply

提交回复
热议问题