Angular 怎么在加载中加入 Loading 提示框

2025-05-15 06:01:49
推荐回答(1个)
回答1:

0、提供一种用过(也许已不是最佳)的思路:

0.1、最外层的 index.html 放个内容为 "Loading..." 的 div;通过最外层 controller 的 $scope.busy 变量,使用 ng-show 控制是否显示;

0.2、需要显示 Loading 时,冒泡 BUSY 事件;最外层 controller 收到 BUSY 事件就将 $scope.busy 置为 true,那个 DIV 就显示了;

0.3、同理,要隐藏就冒泡 NOTBUSY 事件;


1、假设目录结构是:

index.html (这是最外层,body 的 controller 是 mainController;这里写 ng-view)

/partial (各子 view 放这里)


2、index.html 的 body 使用的 mainController 是最外层 controller,在这 mainController 监听 BUSY/NOTBUSY 事件:

index.html 里放着那个显示 "Loading..." 字样的 DIV:

3、使用:

比如在子 view /partial/po.html (使用 poController)中某动作后要显示 Loading 框:

在 poController.js 中: