Angularjs:单个html中的多个partials?
发布时间:2020-12-17 08:41:08 所属栏目:安全 来源:网络整理
导读:是可能检索多个html partials在一个单一的html?我有下面的情况: Template: {header} {main} {footer}/index: header:"Welcome" main:"welcome text" footer:""/help: header:"Help title" main:"faq tips" footer"Back to home" 使用ng-include我必须从服
是可能检索多个html partials在一个单一的html?我有下面的情况:
Template: {header} {main} {footer} /index: header:"Welcome" main:"welcome text" footer:"" /help: header:"Help title" main:"faq tips" footer"Back to home" 使用ng-include我必须从服务器检索6 html。如果我将在一个html中检索多个partials,那么我将从服务器检索2 html,一个用于/ index和一个用于/ help。 >这种情况是一个小例子,真实的情况。 谢谢! 更新04/07/12: 我试图一次更新多个div,具有独特的html检索。我不喜欢这样: function IndexCtrl($scope) { $scope.mainPage = 'partials/index/index.html'; $scope.headerTemplate = 'partials/index/header.html'; $scope.footerTemplate = 'partials/index/footer.html'; } 在模板中使用ng-includes包括这些部分。我认为这不是正确的方法。还有其他方法吗? 谢谢!
模板可以嵌入主要的html。例如,使用以下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'; }]); }]); documentation for the $templateCache service有更多的细节。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |