【问题标题】:How Refresh a list after push? AngularJS/ DB推送后如何刷新列表? AngularJS/数据库
【发布时间】:2023-03-26 12:07:01
【问题描述】:

您好,先生, 我会知道如何在使用 AngularJS 添加、编辑或删除操作后刷新我的列表。

我发布我的控制器和我的 HTML 代码,它可以工作,但我必须刷新所有页面才能查看数据库中的更改。 Ty 表示所有请求。

控制器:

angular.module('myApp').controller('controllerFilm', function(service , $scope ) {

var vm = this;

vm.allFilm = function() {
    service.allFilm().then(
    function(data){//success
        vm.allFilm = data; // accounts list
    },function(err){//error
          console.log("errore di chiamata allFilm");
    });
} 

HTML:

<div ng-controller="controllerFilm as cf">
<button class="button" ng-click="cf.allFilm()">FILM MANAGER</button>
 <br>
 <br>
    <div class="scroll"> 
     <table class="blueTable">  
        <thead>
            <tr>
                <th>ID</th>
                <th>TITLE</th>
                <th>RELASE YEAR</th>
                <th>LENGTH</th>
                <th>EDIT</th>
                <th>DELETE</th>     
            </tr>
        </thead>
        <tbody>
           <tr ng-repeat =
                "film in cf.allFilm  | orderBy : '-filmId' | limitTo : 10">
                    <th>{{film.filmId}}</th>
                    <th>{{film.title}}</th>
                    <th>{{film.relaseYear}}</th>
                    <th>{{film.length}}</th>
                    <th align="center"> <button  
                         ng-click="cf.editFilm(film)">EDIT</button></th>
                    <th align="center"> <button  
                         ng-click="cf.deleteFilm(film)">DELETE</button></th>
          </tr>
      </tbody>
</table>

PS : 我没有发布我的功能编辑和删除..

【问题讨论】:

    标签: angularjs angularjs-ng-repeat refresh


    【解决方案1】:

    虽然更改应该自动应用,因为 AngularJs 有两种方式绑定,但有时,它确实会导致这个问题。将数据设置到列表后尝试调用下面的范围方法。

    $scope.$apply();
    

    P.S:这是一种强制执行摘要循环以立即反映更改的方法。

    【讨论】:

    • 谢谢,我试试。
    猜你喜欢
    • 2017-08-14
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    相关资源
    最近更新 更多