我是angularjs的新手,我已经在计算机上本地运行了一个简单的webapp。我在main.js
应用程序文件中有以下代码:
var webApp = angular.module('webApp', ['ngRoute']);
webApp.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider)
{
$routeProvider.
when('/', {
templateUrl : '/app/pages/home.phtml',
controller : 'mainController'
}).
when('/signin', {
templateUrl : '/app/pages/signin.phtml',
controller : 'signinController'
}).
when('/forgot', {
templateUrl : 'app/pages/forgot.phtml',
controller : 'forgotController'
}).
when('/signup', {
templateUrl : 'app/pages/home.phtml',
controller : 'signupController'
});
$locationProvider.html5Mode(true);
}]);
我想知道在此特定情况下,angularjs的正确方法是什么:假设我要创建home.phtml
多个html文件(或存储在文件中的html元素),换句话说,我想将html页面分解为多个html文件(模板),这样我就可以在必要时分别合并/合并每个元素。
您可以从文档中使用ng-include
作为元素:
<ng-include
src="string"
[onload="string"]
[autoscroll="string"]>
...
</ng-include>
或在任何其他元素内:
<ANY
ng-include="string"
[onload="string"]
[autoscroll="string"]>
...
</ANY>
或作为一个班级:
<ANY class="ng-include: string; [onload: string;] [autoscroll: string;]"> ... </ANY>
基本上,在您要包含其他模板的html文件中,只需添加一个 <ng-include src="yourtemplate.html"></ng-include>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句