将 angular 控制器中的部分视图加载到空文档中

Loading partial views in angular controller into empty document

给定一个只有基本要素的空文档,加载 js 文件和样式表:

<!doctype html>
<html ng-app="labApp">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.min.js"></script>
    <script src="/static/lab.js"></script>
    <link rel="stylesheet" href="/static/local.css" />
    <link rel="stylesheet" href="/static/superhero.min.css" />
  </head>
  <body ng-controller="labController">
  </body>
</html>

以及 lab.js 中的空控制器:

angular.module('labApp', [])
  .controller('labController', function() {
    var lab = this;
  });

如何将部分视图加载到正文中? 我应该使用 jQuery 手动执行此类操作,还是 angular 中有一些隐藏的工具来加载部分?

您可以通过使用 ui-router 渲染不同的视图来做到这一点:https://github.com/angular-ui/ui-router

当加载到您的应用程序中时,您可以像这样在

中包含它
angular.module('app', [ui.router])

当您按照文档进行操作时,设置不同的路由非常容易。祝你好运!