32

是否可以在 Angular js 中将 html 页面嵌入到另一个页面中?

如果是这样,该怎么做?

在他们的教程中,部分没有嵌入到页面中,但它就像您单击其中一个项目时进入的不同页面。(见演示

4

3 回答 3

32

是的,您可以使用ngInclude指令来做到这一点。

请参阅此处的文档和示例:https ://docs.angularjs.org/api/ng/directive/ngInclude

于 2012-12-06T10:46:30.417 回答
7

@Wilt 是对的,但这里有一个更具体的链接和代码示例(来自https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-view

在您的根模板中:

<div ui-view></div>
<div ui-view="chart"></div> 
<div ui-view="data"></div> 

在你的 app.config 函数中

$stateProvider.state("home", {
    views: {
        "": {
            template: "<h1>Some HTML</h1>"
        },
        "chart": {
            templateUrl: "templates/chart.html"
        },
        "data": {
            template: "<data_thing/>"
        }
    }    
})
于 2014-11-27T21:48:44.967 回答
7

如果ng-include不是您需要的,您可能需要查看angular-ui-router模块。它允许您执行嵌套和并行视图......它很棒,灵活,易于使用并且有据可查。 https://github.com/angular-ui/ui-router

于 2013-08-20T10:03:24.510 回答