Angularjs:单HTML倍数谐音? [英] Angularjs: Multiples partials in single html?
问题描述
可以在一个单一的HTML检索倍数HTML谐音?我已经下一个情况:
Is possible retrieve multiples html partials in one single html? I've the next situation:
Template: {header} {main} {footer}
/index: header:"Welcome" main:"welcome text" footer:""
/help: header:"Help title" main:"faq tips" footer"Back to home"
使用
NG-包含我已经中检索从服务器6 HTML。如果我表示读取倍数谐音在一个HTML那么我会检索服务器2仅HTML,一个用于/指数和一个用于/帮助。
using ng-include I've to retreive 6 html from server. If I will retrive multiples partials in one html then I will retrieve 2 html from server only, one for /index and one for /help.
- 这种情况是一个小例子的真实情况。
- 标签的剧本型的 NG-模板不为我工作,因为剧本必须在之前,包括 NG-包含 。
- This situation is a small example the real situation.
- The tag script with type ng-template don't work for me, because the script must be include before of ng-include.
谢谢!
更新12年4月7日:
我寻求同时更新多个分区,具有独特的HTML retreive。我不喜欢这样的:
I seek to update more than one div at a time, with an unique html retreive. I don't like this:
function IndexCtrl($scope) {
$scope.mainPage = 'partials/index/index.html';
$scope.headerTemplate = 'partials/index/header.html';
$scope.footerTemplate = 'partials/index/footer.html';
}
在模板中使用后NG-包括包括这些谐音。我认为这是不正确的方法。还有其他办法吗?
After in the template use ng-includes for include these partials. I think that this is not the correct way. There is other way?
谢谢!
推荐答案
模板可以嵌入在主HTML。例如,下面的 index.html的
:
Templates can be embedded in the main html. For example, with the following index.html
:
<!DOCTYPE html>
<html ng-app=app>
<meta charset=utf-8>
<title>App</title>
<ng-view>Loading...</ng-view>
<script type=text/ng-template id=partial1.html>
<p>foo = {{foo}}</p>
</script>
<script type=text/ng-template id=partial2.html>
<p>Contents of partial2.html</p>
</script>
<script src=app.js></script>
您可以使用下面的 app.js
:
angular.module('app', [], ['$routeProvider', '$controllerProvider', function($routeProvider, $controllerProvider) {
$routeProvider.when('/p1', { templateUrl: 'partial1.html', controller: 'Partial1' });
$controllerProvider.register('Partial1', ['$scope', function($scope) {
$scope.foo = 'bar';
}]);
}]);
为$ templateCache服务有更多的细节文档。
The documentation for the $templateCache service has more details.
这篇关于Angularjs:单HTML倍数谐音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!