3

我想使用包含在一个文件中的 AngularJS 创建一个应用程序。类似于 jQuery Mobile 的多页模板。用 定义几个 div 会很好ng-controller,每个 div 都代表一个带有模板的控制器。相反,angular-ui-router 似乎需要一个templateUrl或一个template字符串。有没有一种优雅的方式来做到这一点?

4

1 回答 1

4

当然,您可以将模板放入script标签指令中,如下所示:

<script type="text/ng-template" id="page1.html">

    <h1>Page 1</h1> <b>markup</b>

</script>

<script type="text/ng-template" id="page2.html">

    <h2>Page 2</h2> here we go

</script>

然后routeProvider以这种方式自定义:

$routeProvider.when('/page1', {

  templateUrl : "page1.html"

}).when('/page2', {

  templateUrl : "page2.html"

}).otherwise({

  redirectTo: 'page1' 

});

示例:http ://plnkr.co/edit/akd7gX?p=preview

于 2013-10-11T11:26:24.493 回答