更改Angularjs路线时,演示文稿脚本的放置位置

Where to place presentation scripts when changing Angularjs routes?

本文关键字:脚本 文稿 位置 置位 Angularjs 更改      更新时间:2024-03-12

这是一个关于Angular的哲学问题。我正在使用这个插件来更改我的应用程序中的路由:

https://github.com/angular-ui/ui-router

但在每次(重新)路由之后,我需要调用更改表示结构的脚本,确切地说,我使用的是Zurb的Foundation,我需要设置调用的程序

$(document).foundation();

我应该把这段代码放在哪里?我感觉它不属于控制器,因为它与View和Zurb的基金会无关。。。

您可以在进入状态时使用onEnter回调来执行任务https://github.com/angular-ui/ui-router/wiki#onenter-和onexit回调

$stateProvider.state("example", {
  template: '<h1>{{title}}</h1>',
  onEnter: function(){
    $(document).foundation();
  }
});