gpt4 book ai didi

javascript - 如何重新加载 AngularJS 部分模板?

转载 作者:数据小太阳 更新时间:2023-10-29 04:12:50 26 4
gpt4 key购买 nike

在我的应用中,主模板有一个月份下拉列表(Jan、Feb ...)。

主模板包含一个 ng-view,使用 routeProvider 加载部分模板。

如何从主模板的 Controller 刷新 ng-view(通过重新运行其 Controller )?

当用户切换到不同的月份时,部分模板内容会刷新。

主模板 HTML:

....
<body class="" ng-controller="Main">
<div ng-view></div>
</body>

路线提供者:

....
.config([ '$routeProvider', function($route) {
$route.when('/module/:module', {
templateUrl : 'partial/module.html',
controller : Module
}).otherwise({
templateUrl : 'partial/dashboard.html',
controller : Dashboard
});
} ]);

主 Controller :

function Main($scope, $cookies) {
...switch month and ajax...
// Reload ng-view goes here
}

最佳答案

AngularJS 广播功能在这里工作......

主模板 Controller :

$scope.switch_month = function(new_month) {
$.ajax({
....
success : function() {
$scope.$broadcast("REFRESH");
},
....
});

};

每个局部模板 Controller :

var refresh = function() {
.... template initialization
};
refresh(); // initialize at once
$scope.$on("REFRESH", refresh); // re-initialize on signal

关于javascript - 如何重新加载 AngularJS 部分模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18690892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com