如何从Angular获得视图渲染时的回调

How to get a callback from Angular for when the view is rendered

本文关键字:回调 视图 Angular      更新时间:2023-09-26

我有一个页面,在那里我更新了一个下拉列表,当项目更新时,我需要在此下拉列表上调用刷新方法。问题是,我不知道如何捕捉到这样的事件。

我认为最好的解决方案是让Angular在渲染视图时为我提供回调。我怎么能有这个?这可能吗?

我的代码是:

    $scope.updateModels = function (id) {
        $http({
            method: "POST",
            url: "/lookup/models",
            params: { makeId: id },
        }).then(function (response) {
            $scope.models = response.data;
            //#mySelsect is NOT yet updated with the options here
            $("#mySelsect").selectpicker("refresh");
        }).finally(function () { });
    };

我正在使用引导程序选择,我需要调用刷新以使项目反映新值。

我今天花了一整天的时间试图解决这个问题,但没有任何运气。

正如我所说,我正在寻找一个回调方法,那将是完美的!恐怕基于超时的方式不是个好主意,我认为。。。

我将编写一个指令来监视模型并调用您的jquery插件