我猜你正在谈论加载partials?你不会真的用控制器加载视图,虽然MAYBE你可以......我会用你的路线加载视图。你的控制器会将你的作用域数据返回到你的局部视图,然后你将它加载到一个ng-view div或其他东西中。因此,例如...
在app.js
(或者无论你怎么称呼它)假设你是myFile.html在同一目录:
angular.
module('app', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/myFile', { templateUrl: 'myFile.html', controller: MyCtrl }).
otherwise({ redirectTo: '/' });
}]);
那么也许在controllers.js文件:
function MyCtrl($scope) {
$scope.foo = "My foo";
}
,然后在myFile.html部分:
<p>{{foo}}</p>
然后你的index.html文件可能看起来someth如:
<!doctype html>
<html ng-app="app">
<head>
<script src="js/angular.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
</head>
<body>
<div ng-controller="MyCtrl">
<div class="container">
<div ng-view></div>
</div> <!-- /container -->
</div>
</body>
</html>
你想在第一个html中添加另一个html文件。 –