一个控制器和多个模板,使用ui-router

One controller and more than one template with ui-router?

本文关键字:使用 ui-router 一个 控制器      更新时间:2023-09-26

我想弄清楚我是否需要为一个控制器注册三个状态。

我有这个错误的模板:404.template.html, 505.template.html和feature.template.html

目前我只注册了ui-router的feature.template.html,我将控制器与他关联。另外两个呢?我是否应该注册和关联同一个控制器?

例如:

$stareProvider
  .state({
    url: '/error',
    templateUrl: '/admin/error/feature.template.html',
    controller: 'ErrorController',
    controllerAs: 'ctrl'
  });

另外两个:404.template.html和505.template.html呢?

谢谢。

你总是可以将相同的控制器分配给不同的状态或指令。如果我没记错的话,它们还将分别实例化,这样它们的作用域变量就不会被彼此共享了。