我在我的angular.js应用程序中使用ng-boilerplate和ui-router。我有一个 3 部分布局、一个顶栏、一个侧边栏和一个主布局。我使用 ng-switch 在主布局中显示不同的视图。这是我的索引.html的样子
<div class="slide-animate" ng-include="HeaderTemplate"></div>
<div class="slide-animate" ng-include="SidebarTemplate"></div>
<div ng-switch on="section">
<div ui-view="secion1" class="secion1" ng-switch-when="secion1"></div>
<div ui-view="secion2" class="secion2" ng-switch-when="secion2"></div>
<div ui-view="secion3" class="secion3" ng-switch-when="secion3"></div>
</div>
我的HeaderTemplate
和SidebarTemplate
正在渲染,但主布局未呈现。
我在$scope
中检查了section
的值。这很好section1
,当我在开发人员工具中检查时,这就是DOM
的样子
<div ng-switch="" on="section">
<!-- ngSwitchWhen: section1 --><div ui-view="section1" class="section1 ng-scope" ng-switch-when="section1"><!-- ui-view-anchor --></div>
<!-- ngSwitchWhen: section2 -->
<!-- ngSwitchWhen: section3 -->
</div>
因此,这里选择了正确的部分,但ui-view
仅显示注释ui-view-anchor
。(我不知道那是什么。我查看了我的 html 源代码,看看我是否正在获得我的section1
、section2
等的模板,我看到我正在获得它们。我看到在templates-app.js
,我正在获取我的部分的html。知道为什么它在获取 html 时不呈现 html 吗?我的$stateProvider
配置如下所示
$stateProvider.state('section1', {
url: '/section1',
views: {
"section1": {
controller: 'Section1Ctrl',
templateUrl: 'section1/section1.tpl.html'
}
},
data: { pageTitle: 'Section 1' }
});
等等。
看起来ui-router v0.2.8
已损坏或与angular.js v1.2.12
不兼容。我切换回ui-router v0.2.7
一切正常